projects
/
rust-lightning
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
326076f
)
Use a tuple struct for MessageType
author
Jeffrey Czyz
<jkczyz@gmail.com>
Mon, 27 Jan 2020 21:44:36 +0000
(13:44 -0800)
committer
Jeffrey Czyz
<jkczyz@gmail.com>
Wed, 5 Feb 2020 20:14:45 +0000
(12:14 -0800)
lightning/src/ln/wire.rs
patch
|
blob
|
history
diff --git
a/lightning/src/ln/wire.rs
b/lightning/src/ln/wire.rs
index 9dedf580f5651ad6732e3958fbf75c22603d1ea5..c1a596b0c6c36397c2f068b6b82c843b721ec3f5 100644
(file)
--- a/
lightning/src/ln/wire.rs
+++ b/
lightning/src/ln/wire.rs
@@
-52,9
+52,7
@@
pub enum Message {
/// A number identifying a message to determine how it is encoded on the wire.
#[derive(Clone, Copy)]
/// A number identifying a message to determine how it is encoded on the wire.
#[derive(Clone, Copy)]
-pub struct MessageType {
- number: u16,
-}
+pub struct MessageType(u16);
impl Message {
/// Returns the type that was used to decode the message payload.
impl Message {
/// Returns the type that was used to decode the message payload.
@@
-91,13
+89,13
@@
impl Message {
impl MessageType {
/// Returns whether the message type is even, indicating both endpoints must support it.
pub fn is_even(&self) -> bool {
impl MessageType {
/// Returns whether the message type is even, indicating both endpoints must support it.
pub fn is_even(&self) -> bool {
- (self.
number
& 1) == 0
+ (self.
0
& 1) == 0
}
}
impl ::std::fmt::Display for MessageType {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
}
}
impl ::std::fmt::Display for MessageType {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
- write!(f, "{}", self.
number
)
+ write!(f, "{}", self.
0
)
}
}
}
}
@@
-180,7
+178,7
@@
pub fn read<R: ::std::io::Read>(buffer: &mut R) -> Result<Message, msgs::DecodeE
Ok(Message::ChannelUpdate(Readable::read(buffer)?))
},
_ => {
Ok(Message::ChannelUpdate(Readable::read(buffer)?))
},
_ => {
- Ok(Message::Unknown(MessageType
{ number: message_type }
))
+ Ok(Message::Unknown(MessageType
(message_type)
))
},
}
}
},
}
}
@@
-209,7
+207,7
@@
pub trait Encode {
/// Returns the type identifying the message payload. Convenience method for accessing
/// [`TYPE`](TYPE).
fn type_id(&self) -> MessageType {
/// Returns the type identifying the message payload. Convenience method for accessing
/// [`TYPE`](TYPE).
fn type_id(&self) -> MessageType {
- MessageType
{ number: Self::TYPE }
+ MessageType
(Self::TYPE)
}
}
}
}
@@
-358,7
+356,7
@@
mod tests {
let mut reader = ::std::io::Cursor::new(buffer);
let message = read(&mut reader).unwrap();
match message {
let mut reader = ::std::io::Cursor::new(buffer);
let message = read(&mut reader).unwrap();
match message {
- Message::Unknown(MessageType
{ number: ::std::u16::MAX }
) => (),
+ Message::Unknown(MessageType
(::std::u16::MAX)
) => (),
_ => panic!("Expected message type {}; found: {}", ::std::u16::MAX, message.type_id()),
}
}
_ => panic!("Expected message type {}; found: {}", ::std::u16::MAX, message.type_id()),
}
}
@@
-394,13
+392,13
@@
mod tests {
#[test]
fn is_even_message_type() {
#[test]
fn is_even_message_type() {
- let message = Message::Unknown(MessageType
{ number: 42 }
);
+ let message = Message::Unknown(MessageType
(42)
);
assert!(message.type_id().is_even());
}
#[test]
fn is_odd_message_type() {
assert!(message.type_id().is_even());
}
#[test]
fn is_odd_message_type() {
- let message = Message::Unknown(MessageType
{ number: 43 }
);
+ let message = Message::Unknown(MessageType
(43)
);
assert!(!message.type_id().is_even());
}
}
assert!(!message.type_id().is_even());
}
}