use rocketman::ingestion::LexiconIngestor; macro_rules! create_commit_collection { ($collection:ident, $nsid:expr, change => $change_fn:expr, delete => $delete_fn:expr $(,)? ) => ( create_commit_collection!( $collection, $nsid, create => $change_fn, update => $change_fn, delete => $delete_fn, ); ); ($collection:ident, $nsid:expr, create => $create_fn:expr, update => $update_fn:expr, delete => $delete_fn:expr $(,)? ) => ( pub struct $collection; struct Ingestor; impl $crate::collections::Collection for $collection { fn new() -> Self { Self } fn get_nsid(&self) -> String { $nsid } fn get_ingestor( &self ) -> Box { Box::new(Ingestor::new()) } } impl Ingestor { pub fn new() -> Self { Self } pub async fn handle_commit( &self, message: rocketman::types::event::Event ) -> anyhow::Result<()> { use rocketman::types::event::Operation; let state = $crate::collections::CommitIngestorState { }; if let Some(commit) = &message.commit { match commit.operation { Operation::Create => ($create_fn)(state, message).await?, Operation::Update => ($update_fn)(state, message).await?, Operation::Delete => ($delete_fn)(state, message).await?, } } else { return Err(anyhow::anyhow!("Message has no commit")); } Ok(()) } } #[async_trait::async_trait] impl rocketman::ingestion::LexiconIngestor for Ingestor { async fn ingest( &self, message: rocketman::types::event::Event ) -> anyhow::Result<()> { self.handle_commit(message).await } } ); } pub mod my_spoor_log_session; pub use my_spoor_log_session::MySpoorLogSession; pub mod my_spoor_log_activity; pub use my_spoor_log_activity::MySpoorLogActivity; struct CommitIngestorState; pub trait Collection { fn new() -> Self; fn get_nsid(&self) -> String; fn get_ingestor(&self) -> Box; }