pub fn del<K: AsRef<[u8]>>(
        &self,
        key: K,
    ) -> Result<Option<PinnedValue>, ()> {
        let _measure = Measure::new(&M.tree_del);

        if self.context.read_only {
            return Ok(None);
        }

        let guard = pin();
        let pin_guard = pin();

        loop {
            let (mut path, existing_key) =
                self.get_internal(key.as_ref(), &guard)?;

            let mut subscriber_reservation =
                self.subscriptions.reserve(&key);

            let (leaf_frag, leaf_ptr) = path.pop().expect(
                "path_for_key should always return a path \
                 of length >= 2 (root + leaf)",
            );
            let node: &Node = leaf_frag.unwrap_base();
            let encoded_key = prefix_encode(&node.lo, key.as_ref());

            let frag = Frag::Del(encoded_key);
            let link = self.context.pagecache.link(
                node.id,
                leaf_ptr.clone(),
                frag,
                &guard,
            );

            match link {
                Ok(_) => {
                    // success
                    if let Some(res) = subscriber_reservation.take() {
                        let event = subscription::Event::Del(
                            key.as_ref().to_vec(),
                        );

                        res.complete(event);
                    }

                    guard.flush();
                    return Ok(existing_key.map(move |r| {
                        PinnedValue::new(r, pin_guard)
                    }));
                }
                Err(Error::CasFailed(_)) => {
                    M.tree_looped();
                    continue;
                }
                Err(other) => return Err(other.danger_cast()),
            }
        }
    }
/// Delete a value, returning the last result if it existed.
///
/// # Examples
///
/// ```
/// let config = sled::ConfigBuilder::new().temporary(true).build();
/// let t = sled::Db::start(config).unwrap();
/// t.set(&[1], vec![1]);
/// assert_eq!(t.del(&*vec![1]).unwrap().unwrap(), vec![1]);
/// assert_eq!(t.del(&*vec![1]), Ok(None));
/// ```
Delete a value, returning the last result if it existed.
Delete a value returning the last result if it existed .
pub fn del<K: AsRef<[u8]>>(
        &self,
        key: K,
    ) -> Result<Option<PinnedValue>, ()> {
        let _measure = Measure::new(&M.tree_del);
        if self.context.read_only {
            return Ok(None);
        }
        let guard = pin();
        let pin_guard = pin();
        loop {
            let (mut path, existing_key) =
                self.get_internal(key.as_ref(), &guard)?;
            let mut subscriber_reservation =
                self.subscriptions.reserve(&key);
            let (leaf_frag, leaf_ptr) = path.pop().expect(
                "path_for_key should always return a path \
                 of length >= 2 (root + leaf)",
            );
            let node: &Node = leaf_frag.unwrap_base();
            let encoded_key = prefix_encode(&node.lo, key.as_ref());
            let frag = Frag::Del(encoded_key);
            let link = self.context.pagecache.link(
                node.id,
                leaf_ptr.clone(),
                frag,
                &guard,
            );
            match link {
                Ok(_) => {
                    // success
                    if let Some(res) = subscriber_reservation.take() {
                        let event = subscription::Event::Del(
                            key.as_ref().to_vec(),
                        );
                        res.complete(event);
                    }
                    guard.flush();
                    return Ok(existing_key.map(move |r| {
                        PinnedValue::new(r, pin_guard)
                    }));
                }
                Err(Error::CasFailed(_)) => {
                    M.tree_looped();
                    continue;
                }
                Err(other) => return Err(other.danger_cast()),
            }
        }
    }
pub fn del < K : AsRef < [ u8 ] > > ( & self , key : K , ) -> Result < Option < PinnedValue > , ( ) > { let _measure = Measure :: new ( & M . tree_del ) ; if self . context . read_only { return Ok ( None ) ; } let guard = pin ( ) ; let pin_guard = pin ( ) ; loop { let ( mut path , existing_key ) = self . get_internal ( key . as_ref ( ) , & guard ) ? ; let mut subscriber_reservation = self . subscriptions . reserve ( & key ) ; let ( leaf_frag , leaf_ptr ) = path . pop ( ) . expect ( " \
 " , ) ; let node : & Node = leaf_frag . unwrap_base ( ) ; let encoded_key = prefix_encode ( & node . lo , key . as_ref ( ) ) ; let frag = Frag :: Del ( encoded_key ) ; let link = self . context . pagecache . link ( node . id , leaf_ptr . clone ( ) , frag , & guard , ) ; match link { Ok ( _ ) => { // success if let Some ( res ) = subscriber_reservation . take ( ) { let event = subscription :: Event :: Del ( key . as_ref ( ) . to_vec ( ) , ) ; res . complete ( event ) ; } guard . flush ( ) ; return Ok ( existing_key . map ( move | r | { PinnedValue :: new ( r , pin_guard ) } ) ) ; } Err ( Error :: CasFailed ( _ ) ) => { M . tree_looped ( ) ; continue ; } Err ( other ) => return Err ( other . danger_cast ( ) ) , } } }
Delete a value, returning the last result if it existed.
Delete a value returning the last result if it existed .
&self
key
K
&self
key
K
examples
None