From c7c26e8900e86f8b2116648e988b1e34c85f4077 Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 24 Jul 2026 14:45:52 +0200 Subject: docs: improve rust docs Signed-off-by: Henry --- crates/types/src/archive.rs | 5 ++++- crates/types/src/instructions.rs | 7 ++++--- crates/types/src/lib.rs | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'crates/types') diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs index 48dc53f..99238ab 100644 --- a/crates/types/src/archive.rs +++ b/crates/types/src/archive.rs @@ -45,7 +45,10 @@ impl Display for TwasmError { impl core::error::Error for TwasmError {} impl Module { - /// Creates a [`Module`] from a slice of bytes. + /// Creates a [`Module`] from internal `twasm` archive bytes. + /// + /// Archives are version-specific and are not validated as untrusted input. + /// Only load archives from a trusted source. pub fn try_from_twasm(wasm: &[u8]) -> Result { let len = validate_magic(wasm)?; postcard::from_bytes(&wasm[len..]).map_err(TwasmError::InvalidArchive) diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index a22279e..cec9d5b 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -116,10 +116,11 @@ pub enum BinOp128 { I64x2Mul, } -/// A WebAssembly Instruction +/// A TinyWasm bytecode instruction. /// -/// These are our own internal bytecode instructions so they may not match the spec exactly. -/// Wasm Bytecode can map to multiple of these instructions. +/// These instructions are an internal, version-specific representation and do not +/// map one-to-one to WebAssembly instructions. Their variants and serialized form +/// may change between TinyWasm releases. /// /// See #[rustfmt::skip] diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index fcac23c..0b4b54c 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -45,8 +45,8 @@ pub mod archive { /// A `TinyWasm` WebAssembly Module /// /// This is the internal representation of a WebAssembly module in `TinyWasm`. -/// [`Module`] are validated before being created, so they are guaranteed to be valid (as long as they were created by `TinyWasm`). -/// This means you should not trust a [`Module`] created by a third party to be valid. +/// Modules produced by the parser are validated by default, but validation can be +/// disabled for trusted input. Do not trust modules or archives from third parties. #[derive(Clone, Default, PartialEq)] #[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] @@ -76,7 +76,7 @@ pub struct ModuleInner { /// Corresponds to the `start` section of the original WebAssembly module. pub start_func: Option, - /// Optimized and validated WebAssembly functions + /// Optimized WebAssembly functions /// /// Contains data from to the `code`, `func`, and `type` sections of the original WebAssembly module. pub funcs: Box<[Arc]>, -- cgit v1.3.1