[−][src]Struct wasmi::MemoryRef
Reference to a memory (See MemoryInstance for details).
This reference has a reference-counting semantics.
Methods from Deref<Target = MemoryInstance>
pub fn initial(&self) -> Pages[src]
pub fn initial(&self) -> PagesReturns number of pages this MemoryInstance was created with.
pub fn maximum(&self) -> Option<Pages>[src]
pub fn maximum(&self) -> Option<Pages>Returns maximum amount of pages this MemoryInstance can grow to.
Returns None if there is no limit set.
Maximum memory size cannot exceed 65536 pages or 4GiB.
pub fn current_size(&self) -> Pages[src]
pub fn current_size(&self) -> PagesReturns current linear memory size.
Maximum memory size cannot exceed 65536 pages or 4GiB.
Example
To convert number of pages to number of bytes you can use the following code:
use wasmi::MemoryInstance; use wasmi::memory_units::*; let memory = MemoryInstance::alloc(Pages(1), None).unwrap(); let byte_size: Bytes = memory.current_size().into(); assert_eq!( byte_size, Bytes(65536), );
pub fn get(&self, offset: u32, size: usize) -> Result<Vec<u8>, Error>[src]
pub fn get(&self, offset: u32, size: usize) -> Result<Vec<u8>, Error>Copy data from memory at given offset.
This will allocate vector for you.
If you can provide a mutable slice you can use get_into.
pub fn get_into(&self, offset: u32, target: &mut [u8]) -> Result<(), Error>[src]
pub fn get_into(&self, offset: u32, target: &mut [u8]) -> Result<(), Error>Copy data from given offset in the memory into target slice.
Errors
Returns Err if the specified region is out of bounds.
pub fn set(&self, offset: u32, value: &[u8]) -> Result<(), Error>[src]
pub fn set(&self, offset: u32, value: &[u8]) -> Result<(), Error>Copy data in the memory at given offset.
pub fn grow(&self, additional: Pages) -> Result<Pages, Error>[src]
pub fn grow(&self, additional: Pages) -> Result<Pages, Error>Increases the size of the linear memory by given number of pages. Returns previous memory size if succeeds.
Errors
Returns Err if attempted to allocate more memory than permited by the limit.
pub fn copy(
&self,
src_offset: usize,
dst_offset: usize,
len: usize
) -> Result<(), Error>[src]
pub fn copy(
&self,
src_offset: usize,
dst_offset: usize,
len: usize
) -> Result<(), Error>Copy contents of one memory region to another.
Semantically equivalent to memmove.
Errors
Returns Err if either of specified regions is out of bounds.
pub fn copy_nonoverlapping(
&self,
src_offset: usize,
dst_offset: usize,
len: usize
) -> Result<(), Error>[src]
pub fn copy_nonoverlapping(
&self,
src_offset: usize,
dst_offset: usize,
len: usize
) -> Result<(), Error>Copy contents of one memory region to another (non-overlapping version).
Semantically equivalent to memcpy.
but returns Error if source overlaping with destination.
Errors
Returns Err if:
- either of specified regions is out of bounds,
- these regions overlaps.
pub fn clear(&self, offset: usize, new_val: u8, len: usize) -> Result<(), Error>[src]
pub fn clear(&self, offset: usize, new_val: u8, len: usize) -> Result<(), Error>Fill the memory region with the specified value.
Semantically equivalent to memset.
Errors
Returns Err if the specified region is out of bounds.
pub fn zero(&self, offset: usize, len: usize) -> Result<(), Error>[src]
pub fn zero(&self, offset: usize, len: usize) -> Result<(), Error>Fill the specified memory region with zeroes.
Errors
Returns Err if the specified region is out of bounds.
pub fn with_direct_access<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R[src]
pub fn with_direct_access<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> RProvides direct access to the underlying memory buffer.
Panics
Any call that requires write access to memory (such as set, clear, etc) made within
the closure will panic. Proceed with caution.
pub fn with_direct_access_mut<R, F: FnOnce(&mut [u8]) -> R>(&self, f: F) -> R[src]
pub fn with_direct_access_mut<R, F: FnOnce(&mut [u8]) -> R>(&self, f: F) -> RTrait Implementations
impl Clone for MemoryRef[src]
impl Clone for MemoryReffn clone(&self) -> MemoryRef[src]
fn clone(&self) -> MemoryRefReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Debug for MemoryRef[src]
impl Debug for MemoryReffn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl Deref for MemoryRef[src]
impl Deref for MemoryReftype Target = MemoryInstance
The resulting type after dereferencing.
fn deref(&self) -> &MemoryInstance[src]
fn deref(&self) -> &MemoryInstanceDereferences the value.
Auto Trait Implementations
Blanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, type Owned = T
fn to_owned(&self) -> T[src]
fn to_owned(&self) -> TCreates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)[src]
fn clone_into(&self, target: &mut T)🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>try_from)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeId🔬 This is a nightly-only experimental API. (get_type_id)
this method will likely be replaced by an associated static
Gets the TypeId of self. Read more
impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut TMutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>,