Files
telnet-server/src/read.rs
Laika 16dd18b400
Some checks failed
Cargo test & clippy / build (push) Has been cancelled
Cargo test & clippy / rust-clippy-analyze (push) Has been cancelled
Cargo security audit / audit (push) Failing after 4s
Initial commit
2025-11-19 23:04:40 +01:00

37 lines
1.2 KiB
Rust

//! Module containing resources for reading data.
//! The reason for this module to exist is "missing" - but mandatory -
//! functionality in the [`std::io::Read`] trait.
use std::io::Error;
/// Trait for extending [`std::io::Read`] to add "missing" functionality
pub trait Read {
/// Reads line to a [`String`], ensuring it is never empty.
/// Spins until a `\n` has been found, so that - even if the buffer is empty
/// at some point - the result is always a non-empty line.
///
/// # Returns
///
/// * `Ok(String)` with a non-empty string, ending with `\n`
/// * `Err(std::io::Error)` if reading fails
///
/// # Examples
///
/// ```ignore
/// use telnet_server::telnet::{Session, State, StateConfig};
/// use crate::telnet_server::read::Read;
///
/// let mut session = Session::new(State::new(&StateConfig::default()), tcp_stream)?;
///
/// // set up session to receive data...
///
/// let incoming = session.read_line_waiting()?;
///
/// assert!(incoming.len() > 0);
/// assert!(incoming.ends_with('\n'));
///
/// Ok(())
/// ```
fn read_line_waiting(&mut self) -> Result<String, Error>;
}