Skip to main content

NixWrite

Trait NixWrite 

Source
pub trait NixWrite: Send {
    type Error: Error;

    // Required methods
    fn version(&self) -> ProtocolVersion;
    fn write_number(
        &mut self,
        value: u64,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn write_slice(
        &mut self,
        buf: &[u8],
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;

    // Provided methods
    fn write_display<D>(
        &mut self,
        msg: D,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send
       where D: Display + Send,
             Self: Sized { ... }
    fn write_value<V>(
        &mut self,
        value: &V,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send
       where V: NixSerialize + Send + ?Sized,
             Self: Sized { ... }
}

Required Associated Types§

Required Methods§

Source

fn version(&self) -> ProtocolVersion

Some types are serialized differently depending on the version of the protocol and so this can be used for implementing that.

Source

fn write_number( &mut self, value: u64, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Write a single u64 to the protocol.

Source

fn write_slice( &mut self, buf: &[u8], ) -> impl Future<Output = Result<(), Self::Error>> + Send

Write a slice of bytes to the protocol.

Provided Methods§

Source

fn write_display<D>( &mut self, msg: D, ) -> impl Future<Output = Result<(), Self::Error>> + Send
where D: Display + Send, Self: Sized,

Write a value that implements std::fmt::Display to the protocol. The protocol uses many small string formats and instead of allocating a String each time we want to write one an implementation of NixWrite can instead use Display to dump these formats to a reusable buffer.

Source

fn write_value<V>( &mut self, value: &V, ) -> impl Future<Output = Result<(), Self::Error>> + Send
where V: NixSerialize + Send + ?Sized, Self: Sized,

Write a value to the protocol. Uses NixSerialize::serialize to write the value.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: NixWrite> NixWrite for &mut T

Source§

type Error = <T as NixWrite>::Error

Source§

fn version(&self) -> ProtocolVersion

Source§

fn write_number( &mut self, value: u64, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Source§

fn write_slice( &mut self, buf: &[u8], ) -> impl Future<Output = Result<(), Self::Error>> + Send

Source§

fn write_display<D>( &mut self, msg: D, ) -> impl Future<Output = Result<(), Self::Error>> + Send
where D: Display + Send, Self: Sized,

Source§

fn write_value<V>( &mut self, value: &V, ) -> impl Future<Output = Result<(), Self::Error>> + Send
where V: NixSerialize + Send + ?Sized, Self: Sized,

Implementors§