//! Generating the strings use super::*; #[derive(Debug)] pub struct GenBodyError(pub String); impl error::Error for GenBodyError{} impl fmt::Display for GenBodyError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "failed to write {:?} to body", self.0) } } pub async fn body(state: State, num: Option, mut output: mpsc::Sender) -> Result<(), GenBodyError> { let chain = state.chain().read().await; if !chain.is_empty() { let filter = state.outbound_filter(); match num { Some(num) if num < state.config().max_gen_size => { //This could DoS `full_body` and writes, potentially. for string in chain.str_iter_for(num) { output.send(filter.filter_owned(string)).await.map_err(|e| GenBodyError(e.0))?; } }, _ => output.send(filter.filter_owned(chain.generate_str())).await.map_err(|e| GenBodyError(e.0))?, } } Ok(()) }