Make deriving the NetworkBehaviour more ergonomic (#782)

This commit is contained in:
Pierre Krieger
2018-12-20 15:21:13 +01:00
committed by GitHub
parent 6be3aca768
commit d10cafa804
7 changed files with 82 additions and 43 deletions

View File

@ -336,6 +336,15 @@ pub trait NetworkBehaviour<TTopology> {
fn poll(&mut self, topology: &mut PollParameters<TTopology>) -> Async<NetworkBehaviourAction<<Self::ProtocolsHandler as ProtocolsHandler>::InEvent, Self::OutEvent>>;
}
/// Used when deriving `NetworkBehaviour`. When deriving `NetworkBehaviour`, must be implemented
/// for all the possible event types generated by the various fields.
// TODO: document how the custom behaviour works and link this here
pub trait NetworkBehaviourEventProcess<TEvent> {
/// Called when one of the fields of the type you're deriving `NetworkBehaviour` on generates
/// an event.
fn inject_event(&mut self, event: TEvent);
}
/// Parameters passed to `poll()` that the `NetworkBehaviour` has access to.
// TODO: #[derive(Debug)]
pub struct PollParameters<'a, TTopology: 'a> {