[][src]Module whasm::grammar::core::unsigned

This module defines the deserialization of unsigned integer numbers (u8, u16, u32, u64 and usize).

let mut iter = [0x2A].iter().copied();
let result: u8 = deserialize(&mut iter).unwrap();
assert_eq!(result, 42);

The WebAssembly Specification specifies that signed integer numbers should be serialized using signed LEB-128 encoding. This means that a number can be encoded with a variable number of bytes.

let mut iter = [0xAA, 0x80, 0x00].iter().copied();
let result: u8 = deserialize(&mut iter).unwrap();
assert_eq!(result, 42);

Deserializing a signed integer will return the Err(_) variant if the iterator is exhausted before completing the deserialization.

let mut iter = [0xAA, 0x80].iter().copied();
let result: Result<u8> = deserialize(&mut iter);
assert!(result.is_err());

Deserialization will also return the Err(_) variant if the encoded numeric value is out of bound for the type being deserialized.

let mut iter = [0xAA, 0x02].iter().copied();
let result: Result<u8> = deserialize(&mut iter);
assert!(result.is_err());