Trait Dump
pub trait Dump {
// Required method
fn dump<W>(
&self,
parent: Option<&Cow<'_, str>>,
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::Dump;
struct VariableLength {
len: u8,
seq: Vec<u8>,
}
impl Dump for VariableLength {
fn dump<W: std::io::Write>(
&self,
parent: Option<&std::borrow::Cow<str>>,
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, &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§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".