let task_bytes = bincode::serialize(&new_task)
.expect("serialize task failed");
println!("task bytes len: {}", task_bytes.len());
let result = database.insert(key, task_bytes)
.expect("insert task to database failed");
match result {
Some(v) => Some(id),
None => {
println!("insert has no return value. len is: {} ", database.len());
None
}
}
Is this the first time you inserted something at that key? The docs say Tree::insert() returns None if this was the first time you are interesting something at a key: https://docs.rs/sled/0.34.2/sled/struct.Tree.html#method.insert. So based off the code snippet above, this is intended behavior. It will only return Some(...) if you insert to the same key again.
Similar to HashMap / BTreeMap::insert, this command returns the previous value if it was set.