use async_trait::async_trait;
use std::{convert::Infallible, fmt::Write};
use super::TransformEntry;
use crate::{
action::transform::result::TransformedEntry,
entry::Entry,
sink::{Sink, Stdout},
};
#[derive(Debug)]
pub struct DebugPrint;
#[async_trait]
impl TransformEntry for DebugPrint {
type Err = Infallible;
async fn transform_entry(&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())
}
}