gix_packetline/line/
blocking_io.rs

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