You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: output_stream.rs
    path of file: ./repos/tunshell/tunshell-client/src/shell/server/fallback
    
    the code of the file until where you have to start completion: use super::ByteChannel;
use io::Write;
use std::{
    io,
    pin::Pin,
    task::{Context, Poll},
};
use tokio::io::AsyncRead;

const CR: u8 = 0x0D;
const LF: u8 = 0x0A;

/// Output byte stream for the fallback terminal
/// Performs conversion of LF to CRLF line endings.
pub(super) struct OutputStream {
    inner: ByteChannel,
    last_byte: Option<u8>,
}

impl Out
    
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        if buf.len() == 0 {
            return Ok(0);
        }

        // Convert LF to CRLF
        let mut written = 0;

        if buf[0] == LF && self.last_byte.unwrap_or(0) != CR {
            self.inner.write_all(&[CR, LF])?;
            written += 1;
        }

        for i in written..buf.len() {
            if i > 0 && buf[i] == LF && buf[i - 1] != CR {
                self.inner.write_all(&buf[written..i])?;
                self.inner.write_all(&[CR, LF])?;
                written = i + 1;
            }
        }

        self.inner.write_all(&buf[written..])?;
        self.last_byte = Some(buf[buf.len() - 1]);

        Ok(buf.len())
    }