Skip to content

Commit a4a1c7a

Browse files
committed
fromstr implemented for channelid
1 parent c00f6aa commit a4a1c7a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

primitives/src/channel.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::error::Error;
22
use std::fmt;
33
use std::ops::Deref;
4+
use std::str::FromStr;
45

56
use chrono::serde::{ts_milliseconds, ts_milliseconds_option, ts_seconds};
67
use chrono::{DateTime, Utc};
@@ -74,6 +75,16 @@ impl fmt::Display for ChannelId {
7475
}
7576
}
7677

78+
impl FromStr for ChannelId {
79+
type Err = FromHexError;
80+
81+
fn from_str(s: &str) -> Result<Self, Self::Err> {
82+
assert_eq!(s.len(), 66);
83+
assert_eq!(&s[0..2], "0x");
84+
Self::from_hex(&s[2..])
85+
}
86+
}
87+
7788
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
7889
#[serde(rename_all = "camelCase")]
7990
pub struct Channel {

0 commit comments

Comments
 (0)