diff --git a/opensmtpd/examples/dummy.rs b/opensmtpd/examples/dummy.rs index 076af59..48e5507 100644 --- a/opensmtpd/examples/dummy.rs +++ b/opensmtpd/examples/dummy.rs @@ -1,17 +1,15 @@ use env_logger::{Builder, Env}; use log::{debug, info}; -use opensmtpd::{event, handlers, Entry, NoContext, Response, SmtpIn}; +use opensmtpd::{event, handlers, Entry, NoContext, SmtpIn}; #[event(Any)] -fn on_event(_context: &mut NoContext, entry: &Entry) -> Response { +fn on_event(_context: &mut NoContext, entry: &Entry) { debug!("Event received: {:?}", entry); - Response::None } #[event(LinkConnect)] -fn on_connect(_context: &mut NoContext, entry: &Entry) -> Response { +fn on_connect(_context: &mut NoContext, entry: &Entry) { info!("New client on session {:x}.", entry.session_id); - Response::None } fn main() { diff --git a/opensmtpd/src/event_handlers.rs b/opensmtpd/src/event_handlers.rs index 2402e75..69ef4dd 100644 --- a/opensmtpd/src/event_handlers.rs +++ b/opensmtpd/src/event_handlers.rs @@ -1,5 +1,4 @@ use crate::entry::{Entry, Event}; -use crate::Response; use std::str::FromStr; #[derive(Clone, Debug, PartialEq)] @@ -10,9 +9,9 @@ pub enum MatchEvent { #[derive(Clone)] pub enum Callback { - NoCtx(fn(&Entry) -> Response), - Ctx(fn(&T, &Entry) -> Response), - CtxMut(fn(&mut T, &Entry) -> Response), + NoCtx(fn(&Entry)), + Ctx(fn(&T, &Entry)), + CtxMut(fn(&mut T, &Entry)), } #[derive(Clone)] @@ -52,14 +51,11 @@ impl EventHandler { } pub fn call(&self, entry: &Entry, context: &mut T) { - let ret = match self.callback { + match self.callback { Callback::NoCtx(f) => f(entry), Callback::Ctx(f) => f(context, entry), Callback::CtxMut(f) => f(context, entry), }; - match ret { - Response::None => {} - } } } @@ -68,10 +64,27 @@ mod test { use crate::*; #[test] - fn test_eventhandler_build() { + fn test_eventhandler_build_noctx() { + // TODO: Remove the :: EventHandler::new( "Any", - |_context: &mut NoContext, _entry: &Entry| -> Response { Response::None }, + Callback::NoCtx::(|_entry: &Entry| {}), + ); + } + + #[test] + fn test_eventhandler_build_ctx() { + EventHandler::new( + "Any", + Callback::Ctx(|_context: &NoContext, _entry: &Entry| {}), + ); + } + + #[test] + fn test_eventhandler_build_ctxmut() { + EventHandler::new( + "Any", + Callback::CtxMut(|_context: &mut NoContext, _entry: &Entry| {}), ); } }