You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
at the current state, this is an obligated pattern modules should do.
Another reason is that for developers is simpler to work with objects as it feels more natural.
My proposal is to have something similar to this for the module trait:
// module namepubstructName2(pubString);// module semverpubstructVersion2(pubi32);// needed by the upper level to decide if allocate a receiver or notpubenumOnEvent<'a>{Nothing,Do(EventHandler<'a>),}impl<'a>OnEvent<'a>{pubfnexecute<F:'a + FnMut() -> Result<(),Box<dyn std::error::Error>>>(f:F) -> Self{Self::Do(EventHandler(Box::new(f)))}}pubstructEventHandler<'a>(Box<dynFnMut() -> Result<(),Box<dyn std::error::Error>> + 'a>);// context similar to the current to send events and errorspubstructCx2{}// raw module configurationpubstructModuleConfig2{}// event#[derive(Debug)]pubstructEvent2{}// module traitpubtraitModule2:Sized{typeConfig:for<'a>TryFrom<&'aModuleConfig2>;fnstart(config:&Self::Config,cx:&Cx2) -> (Name2,Version2,Self);// default for producer only modulesfnon_event<'a>(&'amutself,config:&'aSelf::Config,event:&'aEvent2,cx:&'aCx2,) -> OnEvent<'a>{OnEvent::Nothing}fnon_cfg_change(&mutself,config:&Self::Config,cx:&Cx2,) -> Result<(),Box<dyn std::error::Error>>{Ok(())}// default normal dropfngraceful_stop(self,cx:&Cx2){}}
and move the loop/select block to the upper level into the ModuleManager as it's the same for every module.
The following lines are previews of how modules should look with new traits:
Disclaimer: this code is not complete, but it should resemble what we will get in the end, signatures can be polished. it should compile apart from possible errors adapting to this issue.
Note: maybe the type erasure on the handle function is not needed, even the EventHandler shim with the execute function, but it needs a full test.
The text was updated successfully, but these errors were encountered:
I find the modules start task function a bit strange, expecially the:
at the current state, this is an obligated pattern modules should do.
Another reason is that for developers is simpler to work with objects as it feels more natural.
My proposal is to have something similar to this for the module trait:
and move the
loop/select
block to the upper level into theModuleManager
as it's the same for every module.The following lines are previews of how modules should look with new traits:
Disclaimer: this code is not complete, but it should resemble what we will get in the end, signatures can be polished. it should compile apart from possible errors adapting to this issue.
Note: maybe the type erasure on the handle function is not needed, even the
EventHandler
shim with theexecute
function, but it needs a full test.The text was updated successfully, but these errors were encountered: