Trait nix_compat::wire::ser::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.

Object Safety§

This trait is not object safe.

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§