Skip to main content

Slice

Struct Slice 

Source
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>

Source

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§

Source§

impl<'a> Debug for Slice<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Slice<'a>

Source§

impl<'a> From<&'a [u8]> for Slice<'a>

Source§

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.

Source§

impl From<Bytes> for Slice<'static>

Source§

fn from(bytes: Bytes) -> Self

Create a Slice from LevelDB-allocated bytes.

This is used internally to wrap data that LevelDB allocates and returns to the Rust layer. The Slice becomes responsible for managing the memory and ensuring it’s properly freed when no longer needed.

Source§

impl<'a> Ord for Slice<'a>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a> PartialEq for Slice<'a>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<&[u8]> for Slice<'a>

Source§

fn eq(&self, other: &&[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq<Slice<'_>> for [u8; N]

Source§

fn eq(&self, other: &Slice<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<Slice<'a>> for Vec<u8>

Source§

fn eq(&self, other: &Slice<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<Slice<'a>> for &[u8]

Source§

fn eq(&self, other: &Slice<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<Vec<u8>> for Slice<'a>

Source§

fn eq(&self, other: &Vec<u8>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq<[u8; N]> for Slice<'_>

Source§

fn eq(&self, other: &[u8; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialOrd for Slice<'a>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for Slice<'a>

§

impl<'a> Freeze for Slice<'a>

§

impl<'a> RefUnwindSafe for Slice<'a>

§

impl<'a> Send for Slice<'a>

§

impl<'a> Sync for Slice<'a>

§

impl<'a> Unpin for Slice<'a>

§

impl<'a> UnsafeUnpin for Slice<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.