Sled: db.insert returns None after insert succees, maybe a bug

Created on 21 Aug 2020  路  2Comments  路  Source: spacejam/sled

    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
        }
    }
  1. expected return: Some(id)
  2. actual return: None
  3. sled 0.34.2
  4. rustc 1.45.2
  5. operating Windows10
bug

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings