Trait wasmprinter::Print

source ·
pub trait Print {
    // Required method
    fn write_str(&mut self, s: &str) -> Result<()>;

    // Provided methods
    fn newline(&mut self) -> Result<()> { ... }
    fn start_line(&mut self, binary_offset: Option<usize>) { ... }
    fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()> { ... }
    fn print_custom_section(
        &mut self,
        name: &str,
        binary_offset: usize,
        data: &[u8],
    ) -> Result<bool> { ... }
    fn start_literal(&mut self) -> Result<()> { ... }
    fn start_name(&mut self) -> Result<()> { ... }
    fn start_keyword(&mut self) -> Result<()> { ... }
    fn start_type(&mut self) -> Result<()> { ... }
    fn start_comment(&mut self) -> Result<()> { ... }
    fn reset_color(&mut self) -> Result<()> { ... }
    fn supports_async_color(&self) -> bool { ... }
}
Expand description

Trait used to print WebAssembly modules in this crate.

Instances of this trait are passed to Config::print. Instances of this trait are where the output of a WebAssembly binary goes.

Note that this trait has built-in adapters in the wasmprinter crate:

Required Methods§

source

fn write_str(&mut self, s: &str) -> Result<()>

Writes the given string s in its entirety.

Returns an error for any I/O error.

Provided Methods§

source

fn newline(&mut self) -> Result<()>

Indicates that a newline is being printed.

This can be overridden to hook into the offset at which lines are printed.

source

fn start_line(&mut self, binary_offset: Option<usize>)

Indicates that a new line in the output is starting at the binary_offset provided.

Not all new lines have a binary offset associated with them but this method should be called for new lines in the output. This enables correlating binary offsets to lines in the output.

source

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()>

Enables usage of write! with this trait.

source

fn print_custom_section( &mut self, name: &str, binary_offset: usize, data: &[u8], ) -> Result<bool>

Helper to print a custom section, if needed.

If this output has a custom means of printing a custom section then this can be used to override the default. If Ok(true) is returned then the section will be considered to be printed. Otherwise an Ok(false) return value indicates that the default printing should happen.

source

fn start_literal(&mut self) -> Result<()>

Sets the colors settings for literals ("foo") to be printed.

source

fn start_name(&mut self) -> Result<()>

Sets the colors settings for a name ($foo) to be printed.

source

fn start_keyword(&mut self) -> Result<()>

Sets the colors settings for a keyword ((module ...)) to be printed.

source

fn start_type(&mut self) -> Result<()>

Sets the colors settings for a type ((param i32)) to be printed.

source

fn start_comment(&mut self) -> Result<()>

Sets the colors settings for a comment (;; ...) to be printed.

source

fn reset_color(&mut self) -> Result<()>

Resets colors settings to the default.

source

fn supports_async_color(&self) -> bool

Returns true if the device uses colors without interacting synchronously with a terminal (e.g. ANSI)

Implementors§

source§

impl<T> Print for PrintFmtWrite<T>
where T: Write,

source§

impl<T> Print for PrintIoWrite<T>
where T: Write,

source§

impl<T> Print for PrintTermcolor<T>
where T: WriteColor,