Skip to main content

decode_with

Function decode_with 

Source
pub fn decode_with(bytes: &[u8], limits: &Limits) -> Result<Module, DecodeError>
Expand description

Decodes a module with explicit budgets.

§Errors

As decode, plus DecodeErrorKind::LimitExceeded when the input exceeds one of limits.

§Examples

use bytecode_lang::{decode_with, encode, DecodeErrorKind, Limit, Limits, ModuleBuilder};

let bytes = encode(&ModuleBuilder::new().finish().unwrap());
let mut tight = Limits::default();
tight.max_bytes = 16;
assert_eq!(
    decode_with(&bytes, &tight).unwrap_err().kind(),
    &DecodeErrorKind::LimitExceeded(Limit::Bytes),
);