Struct wasmprinter::Printer

source ·
pub struct Printer { /* private fields */ }
Expand description

Context used for printing a WebAssembly binary.

This is largely only required if you’d like to register custom printers for custom sections in a wasm binary.

Implementations§

source§

impl Printer

source

pub fn new() -> Self

Creates a new Printer object that’s ready to start printing wasm binaries to strings.

source

pub fn print_offsets(&mut self, print: bool)

Whether or not to print binary offsets of each item as comments in the text format whenever a newline is printed.

source

pub fn add_custom_section_printer( &mut self, section: &str, printer: impl FnMut(&mut Printer, usize, &[u8]) -> Result<()> + 'static )

Registers a custom printer function to get invoked whenever a custom section of name section is seen.

This can be used to register printers into a textual format for custom sections, such as by emitting annotations and/or other textual references (maybe comments!)

By default all custom sections are ignored for the text format.

The printer function provided takes three arguments:

  • A &mut Printer, or where to print results to
  • A usize offset which is the start of the offset for the custom section
  • A byte slice which is the actual contents of the custom section.
source

pub fn result_mut(&mut self) -> &mut String

Gets the output result of this Printer, or where all output is going.

source

pub fn print(&mut self, wasm: &[u8]) -> Result<String>

Prints a WebAssembly binary into a String

This function takes an entire wasm binary blob and will print it to the WebAssembly Text Format and return the result as a String.

Trait Implementations§

source§

impl Default for Printer

source§

fn default() -> Printer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Printer

§

impl !Send for Printer

§

impl !Sync for Printer

§

impl Unpin for Printer

§

impl !UnwindSafe for Printer

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.