From 50a37f415e36ae82ca741a14bd97d8b8d76a0374 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Tue, 3 Dec 2019 22:20:45 +0000 Subject: [PATCH] Implement From and From<&'static str> for CommandString --- src/network/message.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/network/message.rs b/src/network/message.rs index 36fa62f3..cd123028 100644 --- a/src/network/message.rs +++ b/src/network/message.rs @@ -43,6 +43,18 @@ impl fmt::Display for CommandString { } } +impl From<&'static str> for CommandString { + fn from(f: &'static str) -> Self { + CommandString(f.into()) + } +} + +impl From for CommandString { + fn from(f: String) -> Self { + CommandString(f.into()) + } +} + impl Encodable for CommandString { #[inline] fn consensus_encode( @@ -320,7 +332,7 @@ mod test { let cs: Result = deserialize(&[0x41u8, 0x6e, 0x64, 0x72, 0x65, 0x77, 0, 0, 0, 0, 0, 0]); assert!(cs.is_ok()); assert_eq!(cs.as_ref().unwrap().to_string(), "Andrew".to_owned()); - assert_eq!(cs.unwrap(), CommandString("Andrew".into())); + assert_eq!(cs.unwrap(), "Andrew".into()); let short_cs: Result = deserialize(&[0x41u8, 0x6e, 0x64, 0x72, 0x65, 0x77, 0, 0, 0, 0, 0]); assert!(short_cs.is_err());