pub fn apply(&self, uart: &mut Uart) -> Result<(), UartCfgError> {
        uart.install_io_tasks(|tx, rx| match self {
            UartCfg::None => Ok((None, None)),
            UartCfg::File { in_path, out_path } => {
                let in_writer = match in_path {
                    Some(in_path) => {
                        let in_file = fs::File::open(&in_path).map_err(UartCfgError::BadFile)?;
                        let in_thread = iothreads::reader_to_chan(in_path.to_string(), in_file, tx);
                        Some(ReaderTask::new(in_thread))
                    }
                    None => None,
                };

                let out_writer = {
                    let out_file = fs::OpenOptions::new()
                        .create(true)
                        .append(true)
                        .open(&out_path)
                        .map_err(UartCfgError::BadFile)?;
                    let out_thread = iothreads::writer_to_chan(out_path.to_string(), out_file, rx);
                    Some(WriterTask::new(out_thread))
                };

                Ok((in_writer, out_writer))
            }
            UartCfg::Stdio => {
                let (in_thread, out_thread) = iothreads::stdio_to_chans(tx, rx);
                Ok((
                    Some(ReaderTask::new(in_thread)),
                    Some(WriterTask::new(out_thread)),
                ))
            }
            UartCfg::Tcp { host, port } => {
                let addr = format!("{}:{}", host, port);
                let in_stream = TcpStream::connect(&addr).map_err(UartCfgError::BadTcp)?;
                let out_stream = in_stream.try_clone().expect("could not clone TcpStream");

                let in_thread = iothreads::reader_to_chan(addr.clone(), in_stream, tx);
                let out_thread = iothreads::writer_to_chan(addr, out_stream, rx);
                Ok((
                    Some(ReaderTask::new(in_thread)),
                    Some(WriterTask::new(out_thread)),
                ))
            }
        })
        .map(drop)
    }
/// Apply uart configuration to the specified uart device
Apply uart configuration to the specified uart device
Apply uart configuration to the specified uart device
pub fn apply(&self, uart: &mut Uart) -> Result<(), UartCfgError> {
        uart.install_io_tasks(|tx, rx| match self {
            UartCfg::None => Ok((None, None)),
            UartCfg::File { in_path, out_path } => {
                let in_writer = match in_path {
                    Some(in_path) => {
                        let in_file = fs::File::open(&in_path).map_err(UartCfgError::BadFile)?;
                        let in_thread = iothreads::reader_to_chan(in_path.to_string(), in_file, tx);
                        Some(ReaderTask::new(in_thread))
                    }
                    None => None,
                };
                let out_writer = {
                    let out_file = fs::OpenOptions::new()
                        .create(true)
                        .append(true)
                        .open(&out_path)
                        .map_err(UartCfgError::BadFile)?;
                    let out_thread = iothreads::writer_to_chan(out_path.to_string(), out_file, rx);
                    Some(WriterTask::new(out_thread))
                };
                Ok((in_writer, out_writer))
            }
            UartCfg::Stdio => {
                let (in_thread, out_thread) = iothreads::stdio_to_chans(tx, rx);
                Ok((
                    Some(ReaderTask::new(in_thread)),
                    Some(WriterTask::new(out_thread)),
                ))
            }
            UartCfg::Tcp { host, port } => {
                let addr = format!("{}:{}", host, port);
                let in_stream = TcpStream::connect(&addr).map_err(UartCfgError::BadTcp)?;
                let out_stream = in_stream.try_clone().expect("could not clone TcpStream");
                let in_thread = iothreads::reader_to_chan(addr.clone(), in_stream, tx);
                let out_thread = iothreads::writer_to_chan(addr, out_stream, rx);
                Ok((
                    Some(ReaderTask::new(in_thread)),
                    Some(WriterTask::new(out_thread)),
                ))
            }
        })
        .map(drop)
    }
pub fn apply ( & self , uart : & mut Uart ) -> Result < ( ) , UartCfgError > { uart . install_io_tasks ( | tx , rx | match self { UartCfg :: None => Ok ( ( None , None ) ) , UartCfg :: File { in_path , out_path } => { let in_writer = match in_path { Some ( in_path ) => { let in_file = fs :: File :: open ( & in_path ) . map_err ( UartCfgError :: BadFile ) ? ; let in_thread = iothreads :: reader_to_chan ( in_path . to_string ( ) , in_file , tx ) ; Some ( ReaderTask :: new ( in_thread ) ) } None => None , } ; let out_writer = { let out_file = fs :: OpenOptions :: new ( ) . create ( true ) . append ( true ) . open ( & out_path ) . map_err ( UartCfgError :: BadFile ) ? ; let out_thread = iothreads :: writer_to_chan ( out_path . to_string ( ) , out_file , rx ) ; Some ( WriterTask :: new ( out_thread ) ) } ; Ok ( ( in_writer , out_writer ) ) } UartCfg :: Stdio => { let ( in_thread , out_thread ) = iothreads :: stdio_to_chans ( tx , rx ) ; Ok ( ( Some ( ReaderTask :: new ( in_thread ) ) , Some ( WriterTask :: new ( out_thread ) ) , ) ) } UartCfg :: Tcp { host , port } => { let addr = format ! ( " " host port ) ; let in_stream = TcpStream :: connect ( & addr ) . map_err ( UartCfgError :: BadTcp ) ? ; let out_stream = in_stream . try_clone ( ) . expect ( " " ) ; let in_thread = iothreads :: reader_to_chan ( addr . clone ( ) , in_stream , tx ) ; let out_thread = iothreads :: writer_to_chan ( addr , out_stream , rx ) ; Ok ( ( Some ( ReaderTask :: new ( in_thread ) ) , Some ( WriterTask :: new ( out_thread ) ) , ) ) } } ) . map ( drop ) }
Apply uart configuration to the specified uart device
Apply uart configuration to the specified uart device
&self
uart
&mut Uart
&self
uart
&mut Uart