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/sentance.rs

26 lines
612 B

//! /sentance/
use super::*;
pub async fn body(state: State, num: Option<usize>, mut output: mpsc::Sender<String>) -> Result<(), gen::GenBodyError>
{
let string = {
let chain = state.chain().read().await;
if chain.is_empty() {
return Ok(());
}
match num {
None => chain.generate_str(),
Some(num) => (0..num).map(|_| chain.generate_str()).join("\n"),
}
};
debug!("Taking {:?} from {:?}" ,num, string);
for sen in sanitise::Sentance::new_iter(&string).take(num.unwrap_or(1))
{
output.send(sen.to_owned()).await.map_err(|e| gen::GenBodyError(e.0))?;
}
Ok(())
}