Trait Alias instrs_core::Size

source ·
trait Size = Serialize + TryFrom<usize> + Into<usize>;
Expand description

Represents a type that can be used to encode the size of a variable-length struct like Vec and String. For example, a u8 will be cheap and efficient, but every vec in the bytecode can only be a maximum of 256 items long.

assert_eq!(
    <Vec::<u8>>::from_bytes::<u8>(&mut [3,1,2,3].as_slice()), 
    Ok(vec![1,2,3])
);
assert_eq!(
    <Vec::<u8>>::from_bytes::<u16>(&mut [3,0, 1,2,3].as_slice()), 
    Ok(vec![1,2,3])
);

Note: You should not use a usize since this makes your bytecode platform-dependent.