cranelift_wasm

Struct Memory

Source
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.

§shared: bool

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

Source

pub const DEFAULT_PAGE_SIZE: u32 = 65_536u32

WebAssembly page sizes are 64KiB by default.

Source

pub const DEFAULT_PAGE_SIZE_LOG2: u8 = 16u8

WebAssembly page sizes are 64KiB (or 2**16) by default.

Source

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.

Source

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.

Source

pub fn page_size(&self) -> u64

Get the size of this memory’s pages, in bytes.

Source

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 Clone for Memory

Source§

fn clone(&self) -> Memory

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Memory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Memory

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Memory, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<MemoryType> for Memory

Source§

fn from(ty: MemoryType) -> Memory

Converts to this type from the input type.
Source§

impl Hash for Memory

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Memory

Source§

fn eq(&self, other: &Memory) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Memory

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Memory

Source§

impl Eq for Memory

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,