use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result;
use super::stream::Stream;
use super::text::Text;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct Line {
stream: Stream,
text: Text,
}
impl Line {
pub fn new(stream: Stream, text: impl Into<Text>) -> Self {
Self {
stream,
text: text.into(),
}
}
pub fn stream(&self) -> Stream {
self.stream
}
pub fn text(&self) -> &Text {
&self.text
}
}
impl Display for Line {
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result {
formatter.write_str(self.text.get())
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::missing_panics_doc)]
use super::*;
#[test]
fn line_is_send_and_sync() {
fn assert_send_and_sync<T: Send + Sync>() {}
assert_send_and_sync::<Line>();
}
#[test]
fn to_string_returns_the_text_of_the_line() {
let line = Line::new(Stream::StandardOutput, "hello");
assert_eq!(line.to_string(), "hello");
}
}