pub fn encode(module: &Module) -> Vec<u8> ⓘExpand description
Encodes a module into its canonical bytes.
Infallible and deterministic: a Module can only be made by
ModuleBuilder::finish or decode, both of which guarantee every
section fits its 32-bit length.
§Examples
use bytecode_lang::{encode, ModuleBuilder};
let module = ModuleBuilder::new().finish().unwrap();
let bytes = encode(&module);
assert_eq!(bytes, encode(&module));
// A 12-byte header, ten 8-byte section headers, and the empty sections'
// counts and option flags.
assert_eq!(bytes.len(), 130);