pub trait LoopExt<M> {
// Required method
fn add_and_fetch<F, W, T, N>(
&mut self,
fsm_wrapper: W,
fun: F,
) -> Result<T, SpawnError<()>>
where W: FnOnce(N) -> M,
F: FnOnce(&mut EarlyScope<'_>) -> Response<(N, T), Void>;
}Expand description
Convenience enhancements to the main loop creator
Required Methods§
Sourcefn add_and_fetch<F, W, T, N>(
&mut self,
fsm_wrapper: W,
fun: F,
) -> Result<T, SpawnError<()>>
fn add_and_fetch<F, W, T, N>( &mut self, fsm_wrapper: W, fun: F, ) -> Result<T, SpawnError<()>>
This method is useful for things that have a state machine and an accessor to it.
Function looks a little bit complicated with generic params. But it solves very useful pattern in easier way.
Examples:
rotor_dns::create_resolve()rotor_carbon::connect_ip()
Usage is simple (carbon example):
ⓘ
let sink = loop_inst.add_and_fetch(Fsm::Carbon, |scope| {
connect_ip(addr, scope)
});Compare it to traditional way:
ⓘ
let mut sink_opt = None;
loop_creator.add_machine_with(|scope| {
let (fsm, sink) = connect_ip(addr, scope).unwrap();
sink_opt = Some(sink);
Ok(Fsm::Carbon(fsm))
}).unwrap();
let sink = sink_opt.unwrap();Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".