mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-19 21:11:22 +00:00
swarm/behaviour: Remove deprecated NetworkBehaviourEventProcess (#2840)
Removes the `NetworkBehaviourEventProcess` and all its associated logic. See deprecation pull request https://github.com/libp2p/rust-libp2p/pull/2784. Find rational in https://github.com/libp2p/rust-libp2p/pull/2751.
This commit is contained in:
@ -48,7 +48,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
let (_, ty_generics, where_clause) = ast.generics.split_for_impl();
|
||||
let multiaddr = quote! {::libp2p::core::Multiaddr};
|
||||
let trait_to_impl = quote! {::libp2p::swarm::NetworkBehaviour};
|
||||
let net_behv_event_proc = quote! {::libp2p::swarm::NetworkBehaviourEventProcess};
|
||||
let either_ident = quote! {::libp2p::core::either::EitherOutput};
|
||||
let network_behaviour_action = quote! {::libp2p::swarm::NetworkBehaviourAction};
|
||||
let into_connection_handler = quote! {::libp2p::swarm::IntoConnectionHandler};
|
||||
@ -71,28 +70,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
quote! {<#(#lf,)* #(#tp,)* #(#cst,)*>}
|
||||
};
|
||||
|
||||
// Whether or not we require the `NetworkBehaviourEventProcess` trait to be implemented.
|
||||
let event_process = {
|
||||
let mut event_process = false;
|
||||
|
||||
for meta_items in ast.attrs.iter().filter_map(get_meta_items) {
|
||||
for meta_item in meta_items {
|
||||
match meta_item {
|
||||
syn::NestedMeta::Meta(syn::Meta::NameValue(ref m))
|
||||
if m.path.is_ident("event_process") =>
|
||||
{
|
||||
if let syn::Lit::Bool(ref b) = m.lit {
|
||||
event_process = b.value
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event_process
|
||||
};
|
||||
|
||||
// The fields of the struct we are interested in (no ignored fields).
|
||||
let data_struct_fields = data_struct
|
||||
.fields
|
||||
@ -121,9 +98,9 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
})
|
||||
.next();
|
||||
|
||||
match (user_provided_out_event_name, event_process) {
|
||||
match user_provided_out_event_name {
|
||||
// User provided `OutEvent`.
|
||||
(Some(name), false) => {
|
||||
Some(name) => {
|
||||
let definition = None;
|
||||
let from_clauses = data_struct_fields
|
||||
.iter()
|
||||
@ -135,7 +112,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
(name, definition, from_clauses)
|
||||
}
|
||||
// User did not provide `OutEvent`. Generate it.
|
||||
(None, false) => {
|
||||
None => {
|
||||
let name: syn::Type = syn::parse_str(&(ast.ident.to_string() + "Event")).unwrap();
|
||||
let definition = {
|
||||
let fields = data_struct_fields
|
||||
@ -170,22 +147,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
let from_clauses = vec![];
|
||||
(name, definition, from_clauses)
|
||||
}
|
||||
// User uses `NetworkBehaviourEventProcess`.
|
||||
(name, true) => {
|
||||
let definition = None;
|
||||
let from_clauses = data_struct_fields
|
||||
.iter()
|
||||
.map(|field| {
|
||||
let ty = &field.ty;
|
||||
quote! {Self: #net_behv_event_proc<<#ty as #trait_to_impl>::OutEvent>}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
(
|
||||
name.unwrap_or_else(|| syn::parse_str("()").unwrap()),
|
||||
definition,
|
||||
from_clauses,
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -545,13 +506,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
out_handler.unwrap_or(quote! {()}) // TODO: See test `empty`.
|
||||
};
|
||||
|
||||
let generate_event_match_arm = if event_process {
|
||||
quote! {
|
||||
std::task::Poll::Ready(#network_behaviour_action::GenerateEvent(event)) => {
|
||||
#net_behv_event_proc::inject_event(self, event)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let generate_event_match_arm = {
|
||||
// If the `NetworkBehaviour`'s `OutEvent` is generated by the derive macro, wrap the sub
|
||||
// `NetworkBehaviour` `OutEvent` in the variant of the generated `OutEvent`. If the
|
||||
// `NetworkBehaviour`'s `OutEvent` is provided by the user, use the corresponding `From`
|
||||
|
Reference in New Issue
Block a user