Skip to content

Commit

Permalink
Add some convenience functions for MemoryTypeBuilder
Browse files Browse the repository at this point in the history
* Add `MemoryType::builder()` to avoid needing to import
  `MemoryTypeBuilder` perhaps.
* Add `MemoryTypeBuilder::new()` as an alias of
  `MemoryTypeBuilder::default()`.
  • Loading branch information
alexcrichton committed Oct 31, 2024
1 parent a82bdd8 commit 4a4936f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crates/wasmtime/src/runtime/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,7 +2545,7 @@ impl TableType {
/// # fn foo() -> wasmtime::Result<()> {
/// use wasmtime::MemoryTypeBuilder;
///
/// let memory_type = MemoryTypeBuilder::default()
/// let memory_type = MemoryTypeBuilder::new()
/// // Set the minimum size, in pages.
/// .min(4096)
/// // Set the maximum size, in pages.
Expand Down Expand Up @@ -2575,6 +2575,21 @@ impl Default for MemoryTypeBuilder {
}

impl MemoryTypeBuilder {
/// Create a new builder for a [`MemoryType`] with the default settings.
///
/// By default memory types have the following properties:
///
/// * The minimum memory size is 0 pages.
/// * The maximum memory size is unspecified.
/// * Memories use 32-bit indexes.
/// * The page size is 64KiB.
///
/// Each option can be configued through the methods on the returned
/// builder.
pub fn new() -> MemoryTypeBuilder {
MemoryTypeBuilder::default()
}

fn validate(&self) -> Result<()> {
if self
.ty
Expand Down Expand Up @@ -2784,6 +2799,14 @@ impl MemoryType {
.unwrap()
}

/// Creates a new [`MemoryTypeBuilder`] to configure all the various knobs
/// of the final memory type being created.
///
/// This is a convenience function for [`MemoryTypeBuilder::new`].
pub fn builder() -> MemoryTypeBuilder {
MemoryTypeBuilder::new()
}

/// Returns whether this is a 64-bit memory or not.
///
/// Note that 64-bit memories are part of the memory64 proposal for
Expand Down

0 comments on commit 4a4936f

Please sign in to comment.