use std::{fmt::Display, path::Path, str::Lines};
use crate::fs::Result;
use super::Error;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Reader {
contents: String,
}
impl Reader {
pub(super) fn new(path: &Path) -> Result<Self> {
let contents = std::fs::read_to_string(path).map_err(Error::Io)?;
Ok(Self { contents })
}
pub fn as_str(&self) -> &str {
&self.contents
}
pub fn lines(&self) -> Lines<'_> {
self.contents.lines()
}
pub fn bytes(&self) -> &[u8] {
self.contents.as_bytes()
}
}
impl Display for Reader {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.contents)
}
}