Add a context object the callbacks
Many filters requires to keep a state within a session. Although it not currently possible to do so, the callback now accept a mutable object of type NoContext. This is the first step, the next one will be to accept any type that implements both Clone and Default. An other step will be to allow the user to define different callback parameters depending on his/her needs.
This commit is contained in:
parent
ea710408d4
commit
11f3712138
5 changed files with 76 additions and 42 deletions
|
@ -13,8 +13,13 @@ pub fn event(attr: TokenStream, input: TokenStream) -> TokenStream {
|
|||
let fn_body = &item.block;
|
||||
let fn_output = &item.decl.output;
|
||||
let output = quote! {
|
||||
fn #fn_name() -> opensmtpd::EventHandler {
|
||||
opensmtpd::EventHandler::new(#attr, |#fn_params| #fn_output #fn_body)
|
||||
// TODO: set the correct EventHandler type
|
||||
fn #fn_name() -> opensmtpd::EventHandler<opensmtpd::NoContext> {
|
||||
// TODO: set the correct Callback type
|
||||
opensmtpd::EventHandler::new(
|
||||
#attr,
|
||||
opensmtpd::Callback::CtxMut(|#fn_params| #fn_output #fn_body)
|
||||
)
|
||||
}
|
||||
};
|
||||
output.into()
|
||||
|
|
Reference in a new issue