mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-17 12:01:23 +00:00
swarm-derive/: Derive Debug for generated OutEvent (#2821)
When generating an `OutEvent` `enum` definition for a user, derive `Debug` for that `enum`. Why not derive `Clone`, `PartialEq` and `Eq` for the generated `enum` definition? While it is fine to require all sub-`OutEvent`s to implement `Debug`, the same does not apply to traits like `Clone`. I suggest users that need `Clone` to define their own `OutEvent`.
This commit is contained in:
@ -159,6 +159,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
|||||||
let visibility = &ast.vis;
|
let visibility = &ast.vis;
|
||||||
|
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
|
#[derive(::std::fmt::Debug)]
|
||||||
#visibility enum #name #impl_generics
|
#visibility enum #name #impl_generics
|
||||||
#where_clause
|
#where_clause
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p::swarm::{NetworkBehaviour, SwarmEvent};
|
use libp2p::swarm::{NetworkBehaviour, SwarmEvent};
|
||||||
use libp2p_swarm_derive::*;
|
use libp2p_swarm_derive::*;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
/// Small utility to check that a type implements `NetworkBehaviour`.
|
/// Small utility to check that a type implements `NetworkBehaviour`.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -275,7 +276,10 @@ fn custom_event_mismatching_field_names() {
|
|||||||
fn bound() {
|
fn bound() {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
struct Foo<T: Copy + NetworkBehaviour> {
|
struct Foo<T: Copy + NetworkBehaviour>
|
||||||
|
where
|
||||||
|
<T as NetworkBehaviour>::OutEvent: Debug,
|
||||||
|
{
|
||||||
ping: libp2p::ping::Ping,
|
ping: libp2p::ping::Ping,
|
||||||
bar: T,
|
bar: T,
|
||||||
}
|
}
|
||||||
@ -288,6 +292,7 @@ fn where_clause() {
|
|||||||
struct Foo<T>
|
struct Foo<T>
|
||||||
where
|
where
|
||||||
T: Copy + NetworkBehaviour,
|
T: Copy + NetworkBehaviour,
|
||||||
|
<T as NetworkBehaviour>::OutEvent: Debug,
|
||||||
{
|
{
|
||||||
ping: libp2p::ping::Ping,
|
ping: libp2p::ping::Ping,
|
||||||
bar: T,
|
bar: T,
|
||||||
@ -489,3 +494,21 @@ fn event_process() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generated_out_event_derive_debug() {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(NetworkBehaviour)]
|
||||||
|
struct Foo {
|
||||||
|
ping: libp2p::ping::Ping,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn require_debug<T>()
|
||||||
|
where
|
||||||
|
T: NetworkBehaviour,
|
||||||
|
<T as NetworkBehaviour>::OutEvent: Debug,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
require_debug::<Foo>();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user