pub fn parse_binary(input: &[u8]) -> Result<Module, ParseError> {
    let mut builder = Module::builder();

    let (input, _) = tuple((tag(PREAMBLE), tag(VERSION)))(input)?;

    let (input, custom_sections) =
        parse_custom_section(input).map_err(|_| ParseError::InvalidBinary)?;
    builder.set_custom_sections(ModuleSection::Custom, custom_sections);

    let (input, types) = parse_type_section(input)?;
    builder.set_function_types(types);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Type, custom_sections);

    let (input, imports) = parse_import_section(input)?;
    builder.set_imports(imports);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Import, custom_sections);

    let (input, signatures) = parse_function_section(input)?;

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Function, custom_sections);

    let (input, tables) = parse_table_section(input)?;
    builder.set_tables(tables);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Table, custom_sections);

    let (input, memories) = parse_memory_section(input)?;
    builder.set_memories(memories);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Memory, custom_sections);

    let (input, globals) = parse_global_section(input)?;
    builder.set_globals(globals);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Global, custom_sections);

    let (input, exports) = parse_export_section(input)?;
    builder.set_exports(exports);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Export, custom_sections);

    let (input, start) = parse_start_section(input)?;
    builder.set_start(start);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Start, custom_sections);

    let (input, elements) = parse_element_section(input)?;
    builder.set_elements(elements);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Element, custom_sections);

    let (input, data_count) = parse_data_count_section(input)?;
    builder.set_data_count(data_count);

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::DataCount, custom_sections);

    let (input, codes) = parse_code_section(input)?;

    validate_function_counts(codes.as_ref(), signatures.as_ref())?;

    builder.set_functions(zip_functions(signatures, codes));

    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Code, custom_sections);

    let (input, data) = parse_data_section(input)?;
    builder.set_data(data);

    let (_, custom_sections) = all_consuming(parse_custom_section)(input)?;
    builder.set_custom_sections(ModuleSection::Data, custom_sections);

    Ok(builder.build())
}
/// Parses the given bytes into a WebAssembly module.
/// The bytes are parsed using the WebAssembly binary format.
/// Requires that no trailing information is present after the last group of custom sections
/// (i.e. valid WebAssembly binary format passed in with trailing data will be treated as invalid).
///
/// Also, the function and code sections must have matching lengths.
///
/// See <https://webassembly.github.io/spec/core/binary/index.html>
///
/// # Examples
/// ## Empty
/// ```rust
/// use wasm_ast::parse_binary;
///
/// let module = parse_binary(b"\x00\x61\x73\x6D\x01\x00\x00\x00").unwrap();
///
/// assert_eq!(module.functions(), None);
/// assert_eq!(module.functions(), None);
/// assert_eq!(module.tables(), None);
/// assert_eq!(module.memories(), None);
/// assert_eq!(module.globals(), None);
/// assert_eq!(module.elements(), None);
/// assert_eq!(module.data(), None);
/// assert_eq!(module.start(), None);
/// assert_eq!(module.imports(), None);
/// assert_eq!(module.exports(), None);
/// assert_eq!(module.data_count(), None);
/// ```
Parses the given bytes into a WebAssembly module.
The bytes are parsed using the WebAssembly binary format.
Requires that no trailing information is present after the last group of custom sections
.

Also, the function and code sections must have matching lengths.

See
Parses the given bytes into a WebAssembly module . The bytes are parsed using the WebAssembly binary format . Requires that no trailing information is present after the last group of custom sections . Also the function and code sections must have matching lengths . See
pub fn parse_binary(input: &[u8]) -> Result<Module, ParseError> {
    let mut builder = Module::builder();
    let (input, _) = tuple((tag(PREAMBLE), tag(VERSION)))(input)?;
    let (input, custom_sections) =
        parse_custom_section(input).map_err(|_| ParseError::InvalidBinary)?;
    builder.set_custom_sections(ModuleSection::Custom, custom_sections);
    let (input, types) = parse_type_section(input)?;
    builder.set_function_types(types);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Type, custom_sections);
    let (input, imports) = parse_import_section(input)?;
    builder.set_imports(imports);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Import, custom_sections);
    let (input, signatures) = parse_function_section(input)?;
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Function, custom_sections);
    let (input, tables) = parse_table_section(input)?;
    builder.set_tables(tables);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Table, custom_sections);
    let (input, memories) = parse_memory_section(input)?;
    builder.set_memories(memories);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Memory, custom_sections);
    let (input, globals) = parse_global_section(input)?;
    builder.set_globals(globals);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Global, custom_sections);
    let (input, exports) = parse_export_section(input)?;
    builder.set_exports(exports);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Export, custom_sections);
    let (input, start) = parse_start_section(input)?;
    builder.set_start(start);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Start, custom_sections);
    let (input, elements) = parse_element_section(input)?;
    builder.set_elements(elements);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Element, custom_sections);
    let (input, data_count) = parse_data_count_section(input)?;
    builder.set_data_count(data_count);
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::DataCount, custom_sections);
    let (input, codes) = parse_code_section(input)?;
    validate_function_counts(codes.as_ref(), signatures.as_ref())?;
    builder.set_functions(zip_functions(signatures, codes));
    let (input, custom_sections) = parse_custom_section(input)?;
    builder.set_custom_sections(ModuleSection::Code, custom_sections);
    let (input, data) = parse_data_section(input)?;
    builder.set_data(data);
    let (_, custom_sections) = all_consuming(parse_custom_section)(input)?;
    builder.set_custom_sections(ModuleSection::Data, custom_sections);
    Ok(builder.build())
}
pub fn parse_binary ( input : & [ u8 ] ) -> Result < Module , ParseError > { let mut builder = Module :: builder ( ) ; let ( input , _ ) = tuple ( ( tag ( PREAMBLE ) , tag ( VERSION ) ) ) ( input ) ? ; let ( input , custom_sections ) = parse_custom_section ( input ) . map_err ( | _ | ParseError :: InvalidBinary ) ? ; builder . set_custom_sections ( ModuleSection :: Custom , custom_sections ) ; let ( input , types ) = parse_type_section ( input ) ? ; builder . set_function_types ( types ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Type , custom_sections ) ; let ( input , imports ) = parse_import_section ( input ) ? ; builder . set_imports ( imports ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Import , custom_sections ) ; let ( input , signatures ) = parse_function_section ( input ) ? ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Function , custom_sections ) ; let ( input , tables ) = parse_table_section ( input ) ? ; builder . set_tables ( tables ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Table , custom_sections ) ; let ( input , memories ) = parse_memory_section ( input ) ? ; builder . set_memories ( memories ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Memory , custom_sections ) ; let ( input , globals ) = parse_global_section ( input ) ? ; builder . set_globals ( globals ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Global , custom_sections ) ; let ( input , exports ) = parse_export_section ( input ) ? ; builder . set_exports ( exports ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Export , custom_sections ) ; let ( input , start ) = parse_start_section ( input ) ? ; builder . set_start ( start ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Start , custom_sections ) ; let ( input , elements ) = parse_element_section ( input ) ? ; builder . set_elements ( elements ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Element , custom_sections ) ; let ( input , data_count ) = parse_data_count_section ( input ) ? ; builder . set_data_count ( data_count ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: DataCount , custom_sections ) ; let ( input , codes ) = parse_code_section ( input ) ? ; validate_function_counts ( codes . as_ref ( ) , signatures . as_ref ( ) ) ? ; builder . set_functions ( zip_functions ( signatures , codes ) ) ; let ( input , custom_sections ) = parse_custom_section ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Code , custom_sections ) ; let ( input , data ) = parse_data_section ( input ) ? ; builder . set_data ( data ) ; let ( _ , custom_sections ) = all_consuming ( parse_custom_section ) ( input ) ? ; builder . set_custom_sections ( ModuleSection :: Data , custom_sections ) ; Ok ( builder . build ( ) ) }
Parses the given bytes into a WebAssembly module.
Parses the given bytes into a WebAssembly module .
input
&[u8]
input
&[u8]
examples
None
empty
```rust
use wasm_ast::parse_binary.




` ` ` rust use wasm_ast :: parse_binary .