/// A function to simplify the implementation of a `sled::Tree` merge operator for a single table.
///
/// **Panics** if serialization or deserialization of keys or values fail.
A function to simplify the implementation of a `sled::Tree` merge operator for a single table.
Panics** if serialization or deserialization of keys or values fail.
A function to simplify the implementation of a ` sled :: Tree ` merge operator for a single table . Panics ** if serialization or deserialization of keys or values fail .
pub fn merge<T, F>(id_key: &[u8], old: Option<&[u8]>, new: &[u8], f: F) -> Vec<u8>
where
    T: Table,
    F: Fn(T::Key, Option<T::Value>, T::Value) -> T::Value,
{
    let (id, key_bytes) = read_id_from_front::<T::Id>(id_key).expect("failed to read table ID");
    assert!(id == T::ID, "Table::ID mismatch during merge");
    let key = bytekey::deserialize(key_bytes).expect("failed to deserialize key");
    let old = old.map(|old| bincode::deserialize(old).expect("failed to deserialize value"));
    let new = bincode::deserialize(new).expect("failed to deserialize value");
    let merged = f(key, old, new);
    bincode::serialize(&merged).expect("failed to deserialize merged value")
}
pub fn merge < T , F > ( id_key : & [ u8 ] , old : Option < & [ u8 ] > , new : & [ u8 ] , f : F ) -> Vec < u8 > where T : Table , F : Fn ( T :: Key , Option < T :: Value > , T :: Value ) -> T :: Value , { let ( id , key_bytes ) = read_id_from_front :: < T :: Id > ( id_key ) . expect ( " " ) ; assert ! ( id T ID " " ) ; let key = bytekey :: deserialize ( key_bytes ) . expect ( " " ) ; let old = old . map ( | old | bincode :: deserialize ( old ) . expect ( " " ) ) ; let new = bincode :: deserialize ( new ) . expect ( " " ) ; let merged = f ( key , old , new ) ; bincode :: serialize ( & merged ) . expect ( " " ) }
A function to simplify the implementation of a `sled::Tree` merge operator for a single table.
A function to simplify the implementation of a ` sled :: Tree ` merge operator for a single table .
id_key
&[u8]
old
Option<&[u8]>
new
&[u8]
f
F