[−][src]Struct memory_slice::Memory
Represents a raw memory range
References to this types are used to alias any kind of objects that can be used as a memory buffer.
Implementations
impl Memory
[src]
pub unsafe fn from_raw_parts<'a>(loc: *const u8, len: usize) -> &'a Self
[src]
Returns a constant memory slice of lenght len
located at loc
Safety
The referenced memory shall be a contiguous readable memory
Contracts
Post-condition - test: loc == ret as * const _ as * const MemLocation
pub unsafe fn from_raw_parts_mut<'a>(loc: *mut u8, len: usize) -> &'a mut Self
[src]
Returns a mutable memory slice of lenght len
located at loc
Safety
The referenced memory shall be a contiguous readable and writable memory
Contracts
Post-condition - test: loc == ret as * mut _ as * mut MemLocation
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]
pub fn is_empty(&self) -> bool
[src]
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]
&mut self,
layout: Layout
) -> (&mut Self, &mut Self, &mut Self)
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]
&mut self,
v: &T
) -> (&mut Self, &mut Self, &mut Self)
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]
&mut self,
n: usize
) -> (&mut Self, &mut [T], &mut Self)
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]
&mut self
) -> (&mut Self, OwnedRef<'_, T>, &mut Self)
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]
&mut self,
n: usize
) -> (&mut Self, OwnedSlice<'_, T>, &mut Self)
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]
&mut self,
val: T
) -> (&mut Self, OwnedRef<'_, T>, &mut Self)
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]
Trait Implementations
impl AsMutMemory for Memory
[src]
fn as_mut_memory(&mut self) -> &mut Memory
[src]
impl Index<Range<usize>> for Memory
[src]
type Output = Self
The returned type after indexing.
fn index(&self, range: Range<usize>) -> &Self::Output
[src]
impl Index<RangeFrom<usize>> for Memory
[src]
type Output = Self
The returned type after indexing.
fn index(&self, range: RangeFrom<usize>) -> &Self::Output
[src]
impl Index<RangeFull> for Memory
[src]
type Output = Self
The returned type after indexing.
fn index(&self, range: RangeFull) -> &Self::Output
[src]
impl Index<RangeInclusive<usize>> for Memory
[src]
type Output = Self
The returned type after indexing.
fn index(&self, range: RangeInclusive<usize>) -> &Self::Output
[src]
impl Index<RangeTo<usize>> for Memory
[src]
type Output = Self
The returned type after indexing.
fn index(&self, range: RangeTo<usize>) -> &Self::Output
[src]
impl Index<RangeToInclusive<usize>> for Memory
[src]
type Output = Self
The returned type after indexing.
fn index(&self, range: RangeToInclusive<usize>) -> &Self::Output
[src]
impl Index<usize> for Memory
[src]
type Output = u8
The returned type after indexing.