pub struct Memory {
pub minimum: u64,
pub maximum: Option<u64>,
pub shared: bool,
pub memory64: bool,
pub page_size_log2: u8,
}
Expand description
WebAssembly linear memory.
Fields§
§minimum: u64
The minimum number of pages in the memory.
maximum: Option<u64>
The maximum number of pages in the memory.
Whether the memory may be shared between multiple threads.
memory64: bool
Whether or not this is a 64-bit memory
page_size_log2: u8
The log2 of this memory’s page size, in bytes.
By default the page size is 64KiB (0x10000; 2**16; 1<<16; 65536) but the
custom-page-sizes proposal allows opting into a page size of 1
.
Implementations§
Source§impl Memory
impl Memory
Sourcepub const DEFAULT_PAGE_SIZE: u32 = 65_536u32
pub const DEFAULT_PAGE_SIZE: u32 = 65_536u32
WebAssembly page sizes are 64KiB by default.
Sourcepub const DEFAULT_PAGE_SIZE_LOG2: u8 = 16u8
pub const DEFAULT_PAGE_SIZE_LOG2: u8 = 16u8
WebAssembly page sizes are 64KiB (or 2**16
) by default.
Sourcepub fn minimum_byte_size(&self) -> Result<u64, SizeOverflow>
pub fn minimum_byte_size(&self) -> Result<u64, SizeOverflow>
Returns the minimum size, in bytes, that this memory must be.
§Errors
Returns an error if the calculation of the minimum size overflows the
u64
return type. This means that the memory can’t be allocated but
it’s deferred to the caller to how to deal with that.
Sourcepub fn maximum_byte_size(&self) -> Result<u64, SizeOverflow>
pub fn maximum_byte_size(&self) -> Result<u64, SizeOverflow>
Returns the maximum size, in bytes, that this memory is allowed to be.
Note that the return value here is not an Option
despite the maximum
size of a linear memory being optional in wasm. If a maximum size
is not present in the memory’s type then a maximum size is selected for
it. For example the maximum size of a 32-bit memory is 1<<32
. The
maximum size of a 64-bit linear memory is chosen to be a value that
won’t ever be allowed at runtime.
§Errors
Returns an error if the calculation of the maximum size overflows the
u64
return type. This means that the memory can’t be allocated but
it’s deferred to the caller to how to deal with that.
Sourcepub fn max_size_based_on_index_type(&self) -> u64
pub fn max_size_based_on_index_type(&self) -> u64
Returns the maximum size memory is allowed to be only based on the index type used by this memory.
For example 32-bit linear memories return 1<<32
from this method.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Memory
impl<'de> Deserialize<'de> for Memory
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<MemoryType> for Memory
impl From<MemoryType> for Memory
Source§fn from(ty: MemoryType) -> Memory
fn from(ty: MemoryType) -> Memory
impl Copy for Memory
impl Eq for Memory
impl StructuralPartialEq for Memory
Auto Trait Implementations§
impl Freeze for Memory
impl RefUnwindSafe for Memory
impl Send for Memory
impl Sync for Memory
impl Unpin for Memory
impl UnwindSafe for Memory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.