Skip to content

feat: add typed memory accessors to Wasmtime::Memory#601

Merged
saulecabrera merged 1 commit into
bytecodealliance:mainfrom
takahashim:feat-typed-memory-access
Jun 2, 2026
Merged

feat: add typed memory accessors to Wasmtime::Memory#601
saulecabrera merged 1 commit into
bytecodealliance:mainfrom
takahashim:feat-typed-memory-access

Conversation

@takahashim

Copy link
Copy Markdown
Contributor

Motivation

Currently, to retrieve an integer value from linear memory, we need to write something like memory.read(out_p, 4).unpack1("l<").
This approach is verbose, difficult to understand, and prone to errors.
Therefore, we want to enable writing memory.read_i32(out_p) instead.

Changes

Introduce paired read/write methods for the WebAssembly numeric types (little-endian):

  • #read_i32 / #write_i32
  • #read_u32 / #write_u32
  • #read_i64 / #write_i64
  • #read_u64 / #write_u64
  • #read_f32 / #write_f32
  • #read_f64 / #write_f64

Out-of-bounds access raises Wasmtime::Error, consistent with #read / #write.

@saulecabrera saulecabrera left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future PRs involving changes to the public API, please open an issue first for discussion. wasmtime-rb's minimal API surface is intentional, we try to keep it as close as upstream as possible. In this case, the change is small enough that I think it is reasonable to land.

@saulecabrera saulecabrera merged commit 1681360 into bytecodealliance:main Jun 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants