Struct Slice Copy item path Source pub struct Slice {
pub index: u8 ,
pub shared_state: SharedState,
pub owned: Option <Vec <u8 >>,
}
Expand description A contiguous block of memory, either preallocated or dynamically allocated.
It serves as a lightweight handle to a memory buffer, allowing for direct manipulation and
shared access. It can either hold a reference to a preallocated memory block or own a
dynamically allocated buffer (via Vec<u8>
).
Unique identifier (index) of the slice in the shared memory pool.
When in back or front mode, tracks the slice within the pool and manages memory reuse. It
allows for quick identification of slices when freeing or reassigning memory. If in alloc
mode, it is set to IGNORE_INDEX
.
Shared state of the memory pool.
When in back or front mode, tracks how many slices are currently in use and ensures proper
synchronization of memory access across multiple contexts.
Optional dynamically allocated buffer.
If present, the slice owns the memory and is responsible for managing its lifecycle. If
None
, the buffer pool is in back or front mode and the slice points to memory managed
by the memory pool. Is Some(Vec<u8>)
when in alloc mode.
Returns the length of the slice in bytes.
If the slice owns its memory (owned
), it returns the length of the owned buffer. If the
slice does not own the memory, it returns 0
.
Checks if the slice is empty.
Returns true
if the slice is empty, i.e., it has no data. Otherwise, returns false
.
Converts the Slice
into a mutable slice of bytes (&mut [u8]
).
Returns the owned buffer if present, otherwise converts the raw pointer and length into a
mutable slice.
Converts the Slice
into an immutable slice of bytes (&[u8]
).
Returns the owned buffer if present, otherwise converts the raw pointer and length into an
immutable slice.
Performs copy-assignment from
source
.
Read more Formats the value using the given formatter.
Read more Toggles the shared state when the slice is dropped, allowing the memory to be reused.
In debug mode, it also tracks the mode
of the slice when it is dropped.
Creates a Slice
from a Vec<u8>
, taking ownership of the vector.
Initializes the Slice
with the vector’s pointer and sets the length to 0
.
Provides immutable slicing access to the specified range within the Slice
.
Uses as_ref
to get a reference to the underlying buffer and returns the specified range.
The returned type after indexing.
Provides immutable slicing access to a range starting from the given index
.
Uses as_ref
to get a reference to the underlying buffer and returns the range.
The returned type after indexing.
Provides immutable access to the entire range of the Slice
.
Uses as_ref
to get a reference to the entire underlying buffer.
The returned type after indexing.
Provides immutable indexing access to the Slice
at the specified position.
Uses as_ref
to get a reference to the underlying buffer and returns the byte at the
index
.
The returned type after indexing.
Provides mutable slicing access to the specified range within the Slice
.
Uses as_mut
to get a mutable reference to the underlying buffer and returns the specified
range.
Provides mutable slicing access to a range starting from the given index
.
Uses as_mut
to get a mutable reference to the underlying buffer and returns the range.
Provides mutable indexing access to the Slice
at the specified position.
Uses as_mut
to get a mutable reference to the underlying buffer and returns the byte at
the index
.
Source § Allows Slice
to be safely transferred between threads.
Slice
contains a raw pointer (*mut u8
), so Rust cannot automatically implement Send
.
The unsafe
block asserts that memory access is thread-safe, relaying on SharedState
and
atomic operations to prevent data races.
Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit
)
Performs copy-assignment from
self
to
dest
.
Read more Returns the argument unchanged.
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From <T> for U
chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.