[][src]Struct memory_slice::BufferAs

#[repr(transparent)]pub struct BufferAs<T>(_);

A buffer of uninitialized memory with same size and alignement as T.

Those buffer implement Deref<Target=Memory> and DerefMut<Target=Memory> so they have the same interface as Memory.

Implementations

impl<T> BufferAs<T>[src]

pub fn new() -> Self[src]

Create an uninitialized buffer.

pub fn zeroed() -> Self[src]

Create a zeroed buffer.

Methods from Deref<Target = Memory>

pub fn as_ptr(&self) -> *const u8[src]

Returns a pointer to the first byte of memory

Contracts

Post-condition - test: ret == self as * const _ as * const MemLocation

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

Returns a mutable pointer to the first byte of memory

Contracts

Post-condition - test: ret == self as * mut _ as * mut MemLocation

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

Returns the memory size.

Contracts

Post-condition - test: ret == mem :: size_of_val(self)

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

Returns true is length is null.

Contracts

Post-condition - test: ret -> self . len() == 0

pub fn alignment(&self) -> usize[src]

Returns the alignment of the memory slice

Contracts

Post-condition - test: self . as_ptr() as usize % ret == 0

Post-condition - test: self . as_ptr() as usize % (2 * ret) == ret

pub fn split_at(&self, mid: usize) -> (&Self, &Self)[src]

Split the memory slice at mid

Contracts

Post-condition - test: self . len() == ret . 0 . len() + ret . 1 . len()

Post-condition - test: ret . 0 . len() == mid

Post-condition - test: self . as_ptr() == ret . 0 . as_ptr()

Post-condition - test: unsafe { ret . 0 . as_ptr() . add(mid) } == ret . 1 . as_ptr()

pub fn split_at_mut<'a>(&mut self, mid: usize) -> (&mut Self, &mut Self)[src]

Mutably split the memory slice at mid

Contracts

Post-condition - test: self . len() == ret . 0 . len() + ret . 1 . len()

Post-condition - test: ret . 0 . len() == mid

Post-condition - test: self . as_ptr() == ret . 0 . as_ptr()

Post-condition - test: unsafe { ret . 0 . as_ptr() . add(mid) } == ret . 1 . as_ptr()

pub fn copy_from_memory(&mut self, other: &Self)[src]

Copy the content of a an other memory slice into self

Contracts

Post-condition - test: unsafe { * (& self . inner as * const [Underlying] as * const [u8]) == * (& other . inner as * const [Underlying] as * const [u8]) }

pub fn copy_within<R: RangeBounds<usize>>(&mut self, range: R, dest: usize)[src]

Move data within this memory slice

pub unsafe fn as_ref_unchecked<T>(&self) -> &T[src]

Returns a reference of type &T that points to the first memory location

Safety

The following pre-condition shall be filled:

  • The memory is at least as aligned as T
  • The memory size is at least as large as T
  • The memory is a valid value representation of type T

Contracts

Pre-condition - debug: self . alignment() >= mem :: align_of :: < T > ()

Pre-condition - debug: self . len() >= mem :: size_of :: < T > ()

Post-condition - test: self . as_ptr() == ret as * const _ as * const MemLocation

pub unsafe fn as_mut_unchecked<T>(&mut self) -> &mut T[src]

Returns a mutable reference of type &mut T that points to the first memory location

Safety

The following pre-condition shall be filled:

  • The memory is at least as aligned as T
  • The memory size is at least as large as T
  • The memory is a valid value representation of type T

Contracts

Pre-condition - debug: self . alignment() >= mem :: align_of :: < T > ()

Pre-condition - debug: self . len() >= mem :: size_of :: < T > ()

Post-condition - test: self . as_ptr() == ret as * mut _ as * const MemLocation

pub unsafe fn as_slice_unchecked<T>(&self, len: usize) -> &[T][src]

Returns a slice of type &[T] that points to the first memory location

Safety

The following pre-condition shall be filled:

  • The memory is at least as aligned as T
  • The memory size is at least as large as len * size_of::<T>::()
  • The memory is a valid value representation of type T

Contracts

Pre-condition - debug: self . alignment() >= mem :: align_of :: < T > ()

Pre-condition - debug: self . len() >= len * mem :: size_of :: < T > ()

Post-condition - test: self . as_ptr() == ret . as_ptr() as * const MemLocation

pub unsafe fn as_mut_slice_unchecked<T>(&mut self, len: usize) -> &mut [T][src]

Returns a mutable slice of type &mut [T] that points to the first memory location

Safety

The following pre-condition shall be filled:

  • The memory is at least as aligned as T
  • The memory size is at least as large as len * size_of::<T>::()
  • The memory is a valid value representation of type T

Contracts

Pre-condition - debug: self . alignment() >= mem :: align_of :: < T > ()

Pre-condition - debug: self . len() >= len * mem :: size_of :: < T > ()

Post-condition - test: self . as_ptr() == ret . as_ptr() as * const MemLocation

pub fn align_for(&self, layout: Layout) -> (&Self, &Self, &Self)[src]

Create a split of the memory for the given layout

Returns 3 memory slice:

  • the first slice represent the alignment padding
  • the second a memory slice sweatable for layout
  • the third is the reaming memory

Contracts

Post-condition - test: ret . 0 . len() < layout . align()

Post-condition - test: ret . 1 . len() == layout . size()

Post-condition - test: ret . 1 . alignment() >= layout . align()

Post-condition - test: (self . alignment() < layout . align()) -> ret . 1 . alignment() == layout . align()

Post-condition - test: (self . alignment() == layout . align()) -> (ret . 0 . len() == 0)

Post-condition - test: ret . 0 . len() + ret . 1 . len() + ret . 2 . len() == self . len()

Post-condition - test: ret . 0 . as_ptr() == self . as_ptr()

Post-condition - test: unsafe { ret . 0 . as_ptr() . add(ret . 0 . len()) } == ret . 1 . as_ptr()

Post-condition - test: unsafe { ret . 1 . as_ptr() . add(ret . 1 . len()) } == ret . 2 . as_ptr()

pub fn align_for_type<T>(&self) -> (&Self, &Self, &Self)[src]

Create a split of the memory for the given type

Returns 3 memory slice:

  • the first slice represent the alignment padding
  • the second a memory slice sweatable for layout
  • the third is the reaming memory

Contracts

Post-condition - test: ret . 1 . len() < mem :: size_of :: < T > ()

Post-condition - test: ret . 1 . alignment() >= mem :: align_of :: < T > ()

pub fn align_for_val<T: ?Sized>(&self, v: &T) -> (&Self, &Self, &Self)[src]

Create a split of the memory for the given value

Returns 3 memory slice:

  • the first slice represent the alignment padding
  • the second a memory slice sweatable for layout
  • the third is the reaming memory

Contracts

Post-condition - test: ret . 1 . len() < mem :: size_of_val(v)

Post-condition - test: ret . 1 . alignment() >= mem :: align_of_val(v)

pub fn align_for_mut(
    &mut self,
    layout: Layout
) -> (&mut Self, &mut Self, &mut Self)
[src]

Create a split of the memory for the given layout

Returns 3 memory slice:

  • the first slice represent the alignment padding
  • the second a memory slice sweatable for layout
  • the third is the reaming memory

Contracts

Post-condition - test: ret . 0 . len() < layout . align()

Post-condition - test: ret . 1 . len() == layout . size()

Post-condition - test: ret . 1 . alignment() >= layout . align()

Post-condition - test: (self . alignment() == layout . align()) -> (ret . 0 . len() == 0)

Post-condition - test: ret . 0 . len() + ret . 1 . len() + ret . 2 . len() == self . len()

Post-condition - test: ret . 0 . as_ptr() == self . as_ptr()

Post-condition - test: unsafe { ret . 0 . as_ptr() . add(ret . 0 . len()) } == ret . 1 . as_ptr()

Post-condition - test: unsafe { ret . 1 . as_ptr() . add(ret . 1 . len()) } == ret . 2 . as_ptr()

pub fn align_for_type_mut<T>(&mut self) -> (&mut Self, &mut Self, &mut Self)[src]

Create a split of the memory for the given type

Returns 3 memory slice:

  • the first slice represent the alignment padding
  • the second a memory slice sweatable for layout
  • the third is the reaming memory

pub fn align_for_val_mut<T: ?Sized>(
    &mut self,
    v: &T
) -> (&mut Self, &mut Self, &mut Self)
[src]

Create a split of the memory for the given value

Returns 3 memory slice:

  • the first slice represent the alignment padding
  • the second a memory slice sweatable for layout
  • the third is the reaming memory

pub unsafe fn get<T>(&self) -> (&Self, &T, &Self)[src]

Returns 2 memory slice and a reference to a value of type T as a tuple:

  • the first element is a slice that represents the alignment padding
  • the second element is reference to a T
  • the third element is the reaming memory

Safety

The following pre-condition shall be filled:

  • The memory refered by the second element is a valid value representation of type T

Panics

This function will panic if the memory slice is not large enough for T and needed alignment padding.

pub unsafe fn get_mut<T>(&mut self) -> (&mut Self, &mut T, &mut Self)[src]

Returns 2 memory slice and a mutable reference to a value of type T as a tuple:

  • the first element is a slice that represents the alignment padding
  • the second element is reference to a T
  • the third element is the reaming memory

Safety

The following pre-condition shall be filled:

  • The memory refered by the second element is a valid value representation of type T

Panics

This function will panic if the memory slice is not large enough for T and needed alignment padding.

pub unsafe fn get_slice<T>(&self, n: usize) -> (&Self, &[T], &Self)[src]

Returns 2 memory slice and a reference to a slice of type [T] and size n as a tuple:

  • the first element is a slice that represents the alignment padding
  • the second element is reference to [T]
  • the third element is the reaming memory

Safety

The following pre-condition shall be filled:

  • The memory refered by the second element is a valid value representation for n T

Panics

This function will panic if the memory slice is not large enough for n T and needed alignment padding.

pub unsafe fn get_mut_slice<T>(
    &mut self,
    n: usize
) -> (&mut Self, &mut [T], &mut Self)
[src]

Returns 2 memory slice and a mutable reference to a slice of type [T] and size n as a tuple:

  • the first element is a slice that represents the alignment padding
  • the second element is reference to [T]
  • the third element is the reaming memory

Safety

The following pre-condition shall be filled:

  • The memory refered by the second element is a valid value representation for n T

Panics

This function will panic if the memory slice is not large enough for n T and needed alignment padding.

pub unsafe fn get_owned_ref<T>(
    &mut self
) -> (&mut Self, OwnedRef<'_, T>, &mut Self)
[src]

Returns an OwnedRef that refers to a &mut T that points to the first memory location

Safety

The following pre-condition shall be filled:

  • The memory is a valid value representation of type T

Panics

This function will panic if the memory slice is not large enough for T and needed alignment padding.

pub unsafe fn get_owned_slice<T>(
    &mut self,
    n: usize
) -> (&mut Self, OwnedSlice<'_, T>, &mut Self)
[src]

Returns an OwnedRef to a mutable slice of type &mut [T] that points to the first memory location

Safety

The following pre-condition shall be filled:

  • The memory is a valid value representation of type T

Panics

This function will panic if the memory slice is not large enough for n T and needed alignment padding.

pub unsafe fn write_unchecked<T: Unpin>(&mut self, val: T) -> &mut T[src]

Writes a value of type T by consuming it and returns a reference to it

Safety

The following pre-condition shall be filled:

  • The memory is at least as aligned as T
  • The memory size is at least as large as T

pub fn write<T: Unpin>(&mut self, val: T) -> (&mut Self, &mut T, &mut Self)[src]

Writes a value of type T by consuming it and returns a reference to it

Panics

This function will panic if the memory slice is not large enough for T and needed alignment padding.

pub fn emplace<T: Unpin>(
    &mut self,
    val: T
) -> (&mut Self, OwnedRef<'_, T>, &mut Self)
[src]

Writes a value of type T by consuming it and returns an OwnedRef that refers to it.

Panics

The following pre-conditions will cause panics:

  • The memory is not as aligned as T
  • The memory size is not as large as T

pub unsafe fn read<T: Unpin>(&self) -> T[src]

Reads a value of type T

Safety

The following pre-conditions shall be fullfilled:

  • The memory size is as large as T
  • The memory has a valid value representation of type T

pub unsafe fn aligned_read<T: Unpin>(&self) -> T[src]

Reads a value of type T

Safety

The following pre-condition shall be fullfilled:

  • The memory has a valid value representation of type T

Panics

This function will panic if the memory slice is not large enough for T and needed alignment padding.

Trait Implementations

impl<T> AsMutMemory for BufferAs<T>[src]

impl<T> Clone for BufferAs<T>[src]

impl<T: Copy> Copy for BufferAs<T>[src]

impl<T: Debug> Debug for BufferAs<T>[src]

impl<T> Deref for BufferAs<T>[src]

type Target = Memory

The resulting type after dereferencing.

impl<T> DerefMut for BufferAs<T>[src]

Auto Trait Implementations

impl<T> Send for BufferAs<T> where
    T: Send

impl<T> Sync for BufferAs<T> where
    T: Sync

impl<T> Unpin for BufferAs<T> where
    T: Unpin

Blanket Implementations

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

impl<T> AsMemory for T where
    T: ?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.