Trait Dump
pub trait Dump {
// Required method
fn dump<'d, W>(
&self,
parent: Option<&Cow<'_, str>>,
doc_overrides: DocOverrides<'d>,
pos: &mut usize,
output: &mut W,
) -> Result<(), Error>
where W: Write;
}Expand description
A functionality to dump the contents of a struct to the output destination.
§Examples
use grib_template_helpers::{DocOverrides, Dump};
struct VariableLength {
len: u8,
seq: Vec<u8>,
}
impl Dump for VariableLength {
fn dump<'d, W: std::io::Write>(
&self,
parent: Option<&std::borrow::Cow<str>>,
doc_overrides: DocOverrides<'d>,
pos: &mut usize,
output: &mut W,
) -> Result<(), std::io::Error> {
writeln!(
output,
"variable-length array (length = {}, content = {:?})",
self.len, self.seq
)
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let var = VariableLength {
len: 3,
seq: vec![1, 2, 3],
};
let mut buf = std::io::Cursor::new(Vec::with_capacity(1024));
let mut pos = 0;
var.dump(None, DocOverrides::empty(), &mut pos, &mut buf)?;
assert_eq!(
String::from_utf8_lossy(buf.get_ref()),
"variable-length array (length = 3, content = [1, 2, 3])\n"
);
Ok(())
}Required Methods§
fn dump<'d, W>(
&self,
parent: Option<&Cow<'_, str>>,
doc_overrides: DocOverrides<'d>,
pos: &mut usize,
output: &mut W,
) -> Result<(), Error>where
W: Write,
fn dump<'d, W>(
&self,
parent: Option<&Cow<'_, str>>,
doc_overrides: DocOverrides<'d>,
pos: &mut usize,
output: &mut W,
) -> Result<(), Error>where
W: Write,
Perform dumping to output.
Users can use the pos argument to output the current byte offset, and
parent to output information about nested structures.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".