You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
genmarkov/src/sanitise/mod.rs

77 lines
1.2 KiB

//! Sanitisers
use super::*;
use std::{
error,
fmt,
};
mod sentance;
pub use sentance::*;
mod word;
pub use word::*;
pub mod filter;
/*
pub fn take_sentance<T: AsyncBufRead+ ?Sized + Unpin, U: AsyncWrite + ?Sized + Unpin>(from: &mut T, to: &mut U) -> Result<usize, Error>
{
todo!()
}*/
#[derive(Debug)]
pub enum Error {
Word(WordError),
Sentance(SentanceError),
}
impl error::Error for Error{}
impl fmt::Display for Error
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
match self {
Self::Word(_) => write!(f, "couldn't extract word"),
Self::Sentance(_) => write!(f, "couldn't extract sentance"),
}
}
}
impl From<WordError> for Error
{
#[inline] fn from(from: WordError) -> Self
{
Self::Word(from)
}
}
impl From<SentanceError> for Error
{
#[inline] fn from(from: SentanceError) -> Self
{
Self::Sentance(from)
}
}
#[cfg(test)]
mod tests
{
use super::*;
#[test]
fn sentance()
{
let string = r#"Hello world.
I am a string, that is a string. Strings, I love them!!!
Owo uwu"#;
let sentances = Sentance::new_iter(string);
for sentance in sentances {
let words = Word::new(sentance);
println!("Word in {:?} -> {:?}", sentance, words);
}
}
}