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<()> { ... }
}
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:
- For users of
std::io::Write
usePrintIoWrite
. - For users of
std::fmt::Write
usePrintFmtWrite
.
Required Methods§
Provided Methods§
sourcefn newline(&mut self) -> Result<()>
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.
sourcefn start_line(&mut self, binary_offset: Option<usize>)
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.
sourcefn write_fmt(&mut self, args: Arguments<'_>) -> Result<()>
fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()>
Enables usage of write!
with this trait.
sourcefn print_custom_section(
&mut self,
name: &str,
binary_offset: usize,
data: &[u8],
) -> Result<bool>
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.
sourcefn start_literal(&mut self) -> Result<()>
fn start_literal(&mut self) -> Result<()>
Sets the colors settings for literals ("foo"
) to be printed.
sourcefn start_name(&mut self) -> Result<()>
fn start_name(&mut self) -> Result<()>
Sets the colors settings for a name ($foo
) to be printed.
sourcefn start_keyword(&mut self) -> Result<()>
fn start_keyword(&mut self) -> Result<()>
Sets the colors settings for a keyword ((module ...)
) to be printed.
sourcefn start_type(&mut self) -> Result<()>
fn start_type(&mut self) -> Result<()>
Sets the colors settings for a type ((param i32)
) to be printed.
sourcefn start_comment(&mut self) -> Result<()>
fn start_comment(&mut self) -> Result<()>
Sets the colors settings for a comment (;; ...
) to be printed.
sourcefn reset_color(&mut self) -> Result<()>
fn reset_color(&mut self) -> Result<()>
Resets colors settings to the default.