pub fn text_to_write(text: &[u8], out: impl Write) -> Result<usize>
Available on crate feature blocking-io only.
Expand description

Write a text message to out, which is assured to end in a newline.

Examples found in repository?
src/line/blocking_io.rs (line 21)
20
21
22
    pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
        encode::text_to_write(self.0, out)
    }
More examples
Hide additional examples
src/write/blocking_io.rs (line 59)
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    fn write(&mut self, mut buf: &[u8]) -> io::Result<usize> {
        if buf.is_empty() {
            return Err(io::Error::new(
                io::ErrorKind::Other,
                "empty packet lines are not permitted as '0004' is invalid",
            ));
        }

        let mut written = 0;
        while !buf.is_empty() {
            let (data, rest) = buf.split_at(buf.len().min(MAX_DATA_LEN));
            written += if self.binary {
                crate::encode::data_to_write(data, &mut self.inner)
            } else {
                crate::encode::text_to_write(data, &mut self.inner)
            }?;
            // subtract header (and trailng NL) because write-all can't handle writing more than it passes in
            written -= U16_HEX_BYTES + usize::from(!self.binary);
            buf = rest;
        }
        Ok(written)
    }