pub trait Output {
// Required method
fn put(&mut self, bytes: &[u8]);
// Provided method
fn reserve(&mut self, additional: usize) { ... }
}Expand description
Where serialized bytes go.
Vec<u8> is the default; a driver can write straight into its own buffer
instead (a zeroizing buffer that wipes on drop, a fixed slab in a passport,
a socket’s send queue). put cannot fail: an Output with a
fixed capacity must grow, or mark itself poisoned and have its owner close
the connection, because a half-written response cannot be recovered
anyway. reserve is a hint and may be ignored.
§Examples
use http_net::Output;
/// Counts bytes without keeping them.
struct Meter(usize);
impl Output for Meter {
fn put(&mut self, bytes: &[u8]) {
self.0 += bytes.len();
}
}
let mut m = Meter(0);
m.put(b"HTTP/1.1 ");
m.put(b"204 No Content\r\n");
assert_eq!(m.0, 25);Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".