[][src]Struct redox_buffer_pool::BufferSlice

pub struct BufferSlice<'a, I: Integer, H: Handle, E: Copy, G: Guard = NoGuard> { /* fields omitted */ }

A slice from the buffer pool, that can be read from or written to as a regular smart pointer.

Implementations

impl<'a, I, H, E, G> BufferSlice<'a, I, H, E, G> where
    I: Integer,
    H: Handle,
    E: Copy,
    G: Guard
[src]

pub fn pool_is_alive(&self) -> bool[src]

Checks whether the pool that owns this slice is still alive, or if it has dropped. Note that this only makes sense for weak buffer slices, since buffer slices tied to a lifetime cannot outlive their pools (checked for at compile time), while strong buffer slices ensure at runtime that they outlive their pools.

For weak buffer slices, this method should be called before doing anything with the slice, since a single deref could make it panic if the buffer isn't there anymore.

pub fn as_slice(&self) -> &[u8][src]

Construct an immutable slice from this buffer.

Panics

This method will panic if this is a weak slice, and the buffer pool has been destroyed..

pub fn try_as_slice(&self) -> Option<&[u8]>[src]

Tries to construct an immutable slice from this buffer, returning None if the pool has been dropped (and hence, this is a weak slice).

pub fn as_slice_mut(&mut self) -> &mut [u8][src]

Construct a mutable slice from this buffer.

Panics

Like as_slice, this method will panic if the buffer pool has been destroyed.

pub fn try_as_slice_mut(&mut self) -> Option<&mut [u8]>[src]

Tries to construct a mutable slice from this buffer, returning None if the pool has been destroyed.

pub unsafe fn unguard(&mut self) -> Option<G>[src]

Forcefully remove a guard from a future, from this slice, returning it if there was a guard already.

Safety

This is unsafe because it allows removing guards set by pending futures; although this is completely fine when there are no pending ones, the buffer slice will be reclaimed without the guard, causing UB if any producer keeps using its pointer.

pub fn guard(&mut self, guard: G) -> Result<(), WithGuardError<G>>[src]

Adds a guard to this buffer, preventing it from deallocating unless the guard accepts that. This is crucial when memory is shared with another component that may be outside this process's address space. If there is a pending io_uring submission or a pending NVME command for instance, this guard will fail if the buffer is in use by a command, and leak the memory instead when dropping.

This will error with WithGuardError if there is already an active guard.

pub fn with_guard<OtherGuard: Guard>(
    self,
    other: OtherGuard
) -> Result<BufferSlice<'a, I, H, E, OtherGuard>, WithGuardError<Self>>
[src]

Tries to add a guard of potentially a different type than the guard type in this slice. Because of that this, this will consume self and construct a different BufferSlice with a different guard type, or error with self if there was already a guard present.

pub fn reclaim(self) -> Result<(), ReclaimError<Self>>[src]

Reclaim the buffer slice, equivalent to dropping but with a Result. If the buffer slice was guarded by a future, this will fail with ReclaimError if the future hadn't completed when this was called.

pub fn offset(&self) -> I[src]

Get the offset of the buffer pool where this was allocated.

pub fn len(&self) -> I[src]

Get the length of the allocation slice.

pub fn capacity(&self) -> I[src]

Get the capacity of the allocation slice. This is almost always the same as the length, but may be larger in case the allocator chose a larger size to align the range afterwards.

pub fn is_empty(&self) -> bool[src]

Check whether the slice is empty or not.

pub fn mmap_offset(&self) -> I[src]

Get the offset of the underlying possibly non-continuously-organized mmap, that was added as part of BufferPool::begin_expand.

pub fn mmap_size(&self) -> I[src]

Get the size of the mmap region this slice was allocated in.

pub fn extra(&self) -> E[src]

Get the extra field from the mmap region this slice belongs to, copied.

Trait Implementations

impl<'a, I: Integer, H: Handle, E: Copy, G: Guard> AsMut<[u8]> for BufferSlice<'a, I, H, E, G>[src]

impl<'a, I: Integer, H: Handle, E: Copy, G: Guard> AsRef<[u8]> for BufferSlice<'a, I, H, E, G>[src]

impl<'a, I: Integer, H: Handle, E: Copy, G: Guard> Borrow<[u8]> for BufferSlice<'a, I, H, E, G>[src]

impl<'a, I: Integer, H: Handle, E: Copy, G: Guard> BorrowMut<[u8]> for BufferSlice<'a, I, H, E, G>[src]

impl<'a, I: Debug + Integer, H: Debug + Handle, E: Debug + Copy, G: Debug + Guard> Debug for BufferSlice<'a, I, H, E, G>[src]

impl<'a, I: Integer, H: Handle, E: Copy, G: Guard> Deref for BufferSlice<'a, I, H, E, G>[src]

type Target = [u8]

The resulting type after dereferencing.

impl<'a, I: Integer, H: Handle, E: Copy, G: Guard> DerefMut for BufferSlice<'a, I, H, E, G>[src]

impl<'a, I, H, E, G> Drop for BufferSlice<'a, I, H, E, G> where
    I: Integer,
    G: Guard,
    E: Copy,
    H: Handle
[src]

impl<'a, I, H, E, G> Send for BufferSlice<'a, I, H, E, G> where
    I: Integer,
    H: Send + Sync + Handle,
    E: Copy + Send,
    G: Send + Guard
[src]

impl<'a, I, H, E, G> Sync for BufferSlice<'a, I, H, E, G> where
    I: Integer,
    H: Send + Sync + Handle,
    E: Copy + Sync,
    G: Sync + Guard
[src]

Auto Trait Implementations

impl<'a, I, H, E, G = NoGuard> !RefUnwindSafe for BufferSlice<'a, I, H, E, G>

impl<'a, I, H, E, G> Unpin for BufferSlice<'a, I, H, E, G> where
    E: Unpin,
    G: Unpin,
    I: Unpin

impl<'a, I, H, E, G = NoGuard> !UnwindSafe for BufferSlice<'a, I, H, E, G>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.