examples: make playground compatibility with v0.16
extern crate pagecache;
extern crate sled;
-use sled::{ConfigBuilder, DbResult, Tree};
+use sled::{ConfigBuilder, Result, Tree};
-fn basic() -> DbResult<(), ()> {
+fn basic() -> Result<(), ()> {
let config = ConfigBuilder::new().temporary(true).build();
let tree = Tree::start(config)?;
@@ -14,15 +14,17 @@ fn basic() -> DbResult<(), ()> {
// set and get
tree.set(k.clone(), v1.clone())?;
- assert_eq!(tree.get(&k), Ok(Some(v1.clone())));
+ assert_eq!(tree.get(&k).unwrap().unwrap(), (v1.clone()));
// compare and swap
- tree.cas(k.clone(), Some(v1.clone()), Some(v2.clone()))
+ tree.cas(k.clone(), Some(&v1.clone()), Some(v2.clone()))
.map_err(|e| e.danger_cast())?;
// scan forward
let mut iter = tree.scan(&*k);
- assert_eq!(iter.next(), Some(Ok((k.clone(), v2.clone()))));
+ let (k1, v1) = iter.next().unwrap().unwrap();
+ assert_eq!(v1, v2.clone());
+ assert_eq!(k1, k.clone());
assert_eq!(iter.next(), None);
// deletion
@@ -31,7 +33,7 @@ fn basic() -> DbResult<(), ()> {
Ok(())
}
-fn merge_operator() -> DbResult<(), ()> {
+fn merge_operator() -> Result<(), ()> {
fn concatenate_merge(
_key: &[u8], // the key being merged
old_value: Option<&[u8]>, // the previous value, if one existed
@@ -58,22 +60,22 @@ fn merge_operator() -> DbResult<(), ()> {
tree.set(k.clone(), vec![0])?;
tree.merge(k.clone(), vec![1])?;
tree.merge(k.clone(), vec![2])?;
- assert_eq!(tree.get(&*k), Ok(Some(vec![0, 1, 2])));
+ assert_eq!(tree.get(&*k).unwrap().unwrap(), (vec![0, 1, 2]));
// sets replace previously merged data,
// bypassing the merge function.
tree.set(k.clone(), vec![3])?;
- assert_eq!(tree.get(&*k), Ok(Some(vec![3])));
+ assert_eq!(tree.get(&*k).unwrap().unwrap(), (vec![3]));
// merges on non-present values will add them
tree.del(&*k)?;
tree.merge(k.clone(), vec![4])?;
- assert_eq!(tree.get(&*k), Ok(Some(vec![4])));
+ assert_eq!(tree.get(&*k).unwrap().unwrap(), (vec![4]));
Ok(())
}
-fn main() -> DbResult<(), ()> {
+fn main() -> Result<(), ()> {
basic()?;
merge_operator()
}
