gix_packetline_blocking/line/
blocking_io.rs

1// DO NOT EDIT - this is a copy of gix-packetline/src/line/blocking_io.rs. Run `just copy-packetline` to update it.
2
3use std::io;
4
5use crate::{encode, BandRef, Channel, ErrorRef, PacketLineRef, TextRef};
6
7impl BandRef<'_> {
8    /// Serialize this instance to `out`, returning the amount of bytes written.
9    ///
10    /// The data written to `out` can be decoded with [`Borrowed::decode_band()]`.
11    pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
12        match self {
13            BandRef::Data(d) => encode::band_to_write(Channel::Data, d, out),
14            BandRef::Progress(d) => encode::band_to_write(Channel::Progress, d, out),
15            BandRef::Error(d) => encode::band_to_write(Channel::Error, d, out),
16        }
17    }
18}
19
20impl TextRef<'_> {
21    /// Serialize this instance to `out`, appending a newline if there is none, returning the amount of bytes written.
22    pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
23        encode::text_to_write(self.0, out)
24    }
25}
26
27impl ErrorRef<'_> {
28    /// Serialize this line as error to `out`.
29    ///
30    /// This includes a marker to allow decoding it outside a side-band channel, returning the amount of bytes written.
31    pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
32        encode::error_to_write(self.0, out)
33    }
34}
35
36impl PacketLineRef<'_> {
37    /// Serialize this instance to `out` in git `packetline` format, returning the amount of bytes written to `out`.
38    pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
39        match self {
40            PacketLineRef::Data(d) => encode::data_to_write(d, out),
41            PacketLineRef::Flush => encode::flush_to_write(out),
42            PacketLineRef::Delimiter => encode::delim_to_write(out),
43            PacketLineRef::ResponseEnd => encode::response_end_to_write(out),
44        }
45    }
46}