I am new and lost in Rust a bit.
I would like to add keys and values to a data store that has a put function that takes two byte string literals:
batch.put(b"foxi", b"maxi");
I generate a bunch of these k-v pairs:
for _ in 1..1000000 {
let mut ivec = Vec::new();
let s1: u8 = rng.gen();
let s2: u8 = rng.gen();
ivec.push(s1);
ivec.push(s2);
debug!("Adding key: {} and value {}", s1, s2);
vec.push(ivec);
}
let _ = database::write(db, vec);
I have a fn that tries to add them:
pub fn write(db: DB, vec: Vec<Vec<u8>>) {
let batch = WriteBatch::new();
for v in vec {
batch.put(v[0], v[1]);
}
db.write(&batch).unwrap();
}
When I try to compile this I get:
error[E0308]: mismatched types
--> src/database.rs:17:19
|
17 | batch.put(v[0], v[1]);
| ^^^^ expected &[u8], found u8
|
= note: expected type `&[u8]`
found type `u8`
error[E0308]: mismatched types
--> src/database.rs:17:25
|
17 | batch.put(v[0], v[1]);
| ^^^^ expected &[u8], found u8
|
= note: expected type `&[u8]`
found type `u8`
I was ping-ponging with the borrow checker for a while now but I could not get it working. What is the best way to have byte literal strings from u8s?