Skip to content

Commit 4c81318

Browse files
committed
Move trait bounds on wire::Type from use to the trait itself
`wire::Type` is only (publicly) used as the `CustomMessage` associated type in `CustomMessageReader`, where it has additional trait bounds on `Debug` and `Writeable`. The documentation for `Type` even mentions that you need to implement `Writeable` because this is the one place it is used. To make this more clear, we move the type bounds onto the trait itself and not on the associated type. This is also the only practical way to build C bindings for `Type` as we cannot have a concrete, single, `Type` struct in C which only optionally implements various subtraits, at least not without runtime checking of the type bounds.
1 parent 34dd7c5 commit 4c81318

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lightning/src/ln/wire.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use util::ser::{Readable, Writeable, Writer};
2020
/// decoders.
2121
pub trait CustomMessageReader {
2222
/// The type of the message decoded by the implementation.
23-
type CustomMessage: core::fmt::Debug + Type + Writeable;
23+
type CustomMessage: Type;
2424
/// Decodes a custom message to `CustomMessageType`. If the given message type is known to the
2525
/// implementation and the message could be decoded, must return `Ok(Some(message))`. If the
2626
/// message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
@@ -245,12 +245,12 @@ pub(crate) use self::encode::Encode;
245245
/// Defines a type identifier for sending messages over the wire.
246246
///
247247
/// Messages implementing this trait specify a type and must be [`Writeable`].
248-
pub trait Type {
248+
pub trait Type: core::fmt::Debug + Writeable {
249249
/// Returns the type identifying the message payload.
250250
fn type_id(&self) -> u16;
251251
}
252252

253-
impl<T> Type for T where T: Encode {
253+
impl<T: core::fmt::Debug + Writeable> Type for T where T: Encode {
254254
fn type_id(&self) -> u16 {
255255
T::TYPE
256256
}

0 commit comments

Comments
 (0)