Skip to main content

Output

Trait Output 

Source
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§

Source

fn put(&mut self, bytes: &[u8])

Appends bytes.

Provided Methods§

Source

fn reserve(&mut self, additional: usize)

Says that about additional more bytes are coming; an implementation may grow once instead of several times. Optional.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Output for Vec<u8>

Source§

fn put(&mut self, bytes: &[u8])

Source§

fn reserve(&mut self, additional: usize)

Source§

impl<O: Output + ?Sized> Output for &mut O

Source§

fn put(&mut self, bytes: &[u8])

Source§

fn reserve(&mut self, additional: usize)

Implementors§