pub trait Sink {
// Required method
fn put(&mut self, bytes: &[u8]) -> Result<(), Full>;
// Provided method
fn remaining(&self) -> Option<usize> { ... }
}Expand description
The output abstraction every writer takes.
put appends all of bytes or fails with Full. remaining reports
how many more bytes fit, when the sink knows; writers that produce a value
in several put calls check it first, so a sink that knows its room never
holds half a value after an error.
§Examples
use parse_net::{Full, Sink};
/// A sink that keeps only the last byte it was given.
struct Last(Option<u8>);
impl Sink for Last {
fn put(&mut self, bytes: &[u8]) -> Result<(), Full> {
if let Some(&b) = bytes.last() {
self.0 = Some(b);
}
Ok(())
}
}
let mut last = Last(None);
parse_net::write::write_token(b"gzip", &mut last)?;
assert_eq!(last.0, Some(b'p'));Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".