diff options
| author | Henry <mail@henrygressmann.de> | 2026-04-12 21:16:49 +0200 |
|---|---|---|
| committer | Henry <mail@henrygressmann.de> | 2026-04-12 21:16:49 +0200 |
| commit | 80cf746b50513af77203f382f5f53bd036087358 (patch) | |
| tree | a9493ec0a69caba0dd82e568b6556340be306e0a /crates/types | |
| parent | d89729df921d39f81fe8a43990678853deb1edde (diff) | |
feat: remove lifetimes from runtime objects
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/types')
| -rw-r--r-- | crates/types/src/lib.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 737c04e..f74336c 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -336,6 +336,31 @@ pub struct GlobalType { pub ty: ValType, } +impl GlobalType { + /// Create a new global type. + pub const fn new(ty: ValType, mutable: bool) -> Self { + Self { mutable, ty } + } + + /// Set a different value type. + pub const fn with_ty(mut self, ty: ValType) -> Self { + self.ty = ty; + self + } + + /// Set global mutability. + pub const fn with_mutable(mut self, mutable: bool) -> Self { + self.mutable = mutable; + self + } +} + +impl Default for GlobalType { + fn default() -> Self { + Self::new(ValType::I32, false) + } +} + #[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] @@ -367,6 +392,7 @@ pub struct MemoryType { } impl MemoryType { + /// Create a new memory type. pub const fn new( arch: MemoryArch, page_count_initial: u64, @@ -405,6 +431,36 @@ impl MemoryType { pub const fn max_size(&self) -> u64 { self.page_count_max() * self.page_size() } + + /// Set a different memory architecture. + pub const fn with_arch(mut self, arch: MemoryArch) -> Self { + self.arch = arch; + self + } + + /// Set a different initial page count. + pub const fn with_page_count_initial(mut self, page_count_initial: u64) -> Self { + self.page_count_initial = page_count_initial; + self + } + + /// Set a different maximum page count. + pub const fn with_page_count_max(mut self, page_count_max: Option<u64>) -> Self { + self.page_count_max = page_count_max; + self + } + + /// Set a different page size. + pub const fn with_page_size(mut self, page_size: Option<u64>) -> Self { + self.page_size = page_size; + self + } +} + +impl Default for MemoryType { + fn default() -> Self { + Self::new(MemoryArch::I32, 0, None, None) + } } #[derive(Copy, Clone, PartialEq, Eq, Hash)] |
