use std::{convert::Infallible, fmt::Write};
use super::Transform;
use crate::{
actions::transforms::result::TransformedEntry,
entry::Entry,
sinks::{Sink, Stdout},
};
#[derive(Debug)]
pub struct DebugPrint;
impl Transform for DebugPrint {
type Err = Infallible;
async fn transform_entry(&mut self, entry: Entry) -> Result<Vec<TransformedEntry>, Self::Err> {
let mut msg = entry.msg;
msg.body = {
let mut body = msg.body.unwrap_or_else(|| "None".to_owned());
_ = write!(
body,
"\n\nid: {:?}\n\nraw_contents: {:?}",
entry.id, entry.raw_contents
);
Some(body)
};
Stdout
.send(&msg, None, Some("debug print"))
.await
.expect("stdout is unavailable");
Ok(Vec::new())
}
}