sled/
prefix.rs

1use super::*;
2
3pub(crate) fn empty() -> &'static [u8] {
4    &[]
5}
6
7pub(crate) fn reencode(
8    old_prefix: &[u8],
9    old_encoded_key: &IVec,
10    new_prefix_length: usize,
11) -> IVec {
12    let new_encoded_key: Vec<u8> = old_prefix
13        .iter()
14        .chain(old_encoded_key.iter())
15        .skip(new_prefix_length)
16        .copied()
17        .collect();
18
19    IVec::from(new_encoded_key)
20}
21
22pub(crate) fn decode(old_prefix: &[u8], old_encoded_key: &[u8]) -> IVec {
23    let mut decoded_key =
24        Vec::with_capacity(old_prefix.len() + old_encoded_key.len());
25    decoded_key.extend_from_slice(old_prefix);
26    decoded_key.extend_from_slice(old_encoded_key);
27
28    IVec::from(decoded_key)
29}