pub struct Slice<'a> { /* private fields */ }Expand description
Slice is the core interface for exchanging data with LevelDB.
Slice can exist in one of two states:
- Borrowed: References a byte array
- Owned: Owns LevelDB-allocated byte data
§Data Access
Use the as_bytes() method to obtain a reference to the internal data.
§Important: Iterator Lifetime Warning
When a Slice is returned from an iterator, it only holds a reference to LevelDB’s internal data. After the iterator continues iteration (calling next(), seek(), etc.), the data references in previously returned Slices may become invalid. If longer ownership is required, consider copying the data:
§Memory Management
- Borrowed state: Slice does not own data, lifetime must not exceed original data
- Owned state: Slice owns LevelDB-allocated memory and automatically frees it on Drop
Implementations§
Source§impl<'a> Slice<'a>
impl<'a> Slice<'a>
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Get a byte slice reference to the internal data.
§Returns
Returns a &[u8] reference to the internal data. Regardless of whether the Slice
is in Borrowed or Owned state, the actual data content can be accessed through this method.
§Important Lifetime Warning
Critical: If this Slice comes from an iterator, the returned reference’s lifetime is limited by the iterator’s state. This reference may become invalid after the iterator continues iteration.
Trait Implementations§
impl<'a> Eq for Slice<'a>
Source§impl<'a> From<&'a [u8]> for Slice<'a>
impl<'a> From<&'a [u8]> for Slice<'a>
Source§fn from(data: &'a [u8]) -> Self
fn from(data: &'a [u8]) -> Self
Create a Slice from a byte slice.
This constructor is intended for creating Slice instances from user owned data. The Slice will borrow the data, so the original data must outlive the Slice.
Use this when user owned byte data needs to be passed to LevelDB operations like put(), delete(), or get(). The Slice will only hold a reference, avoiding data copying.