[][src]Function wit_text::parse_bytes

pub fn parse_bytes(bytes: &[u8]) -> Result<Cow<[u8]>>

Parses in-memory bytes as either the text format or a binary WebAssembly module.

This function will attempt to interpret the given bytes as one of two options:

  • A utf-8 string which is a *.wat file to be parsed.
  • A binary WebAssembly file starting with b"\0asm"

If the input is a string then it will be parsed as *.wat, and then after parsing it will be encoded back into a WebAssembly binary module. If the input is a binary that starts with b"\0asm" it will be returned verbatim. Everything that doesn't start with b"\0asm" will be parsed as a utf-8 *.wat file, returning errors as appropriate.

Errors

In addition to all of the errors that can be returned from parse_str, this function will also return an error if the input does not start with b"\0asm" and is invalid utf-8. (failed to even try to call parse_str).