Skip to content

Commit 687f3db

Browse files
committed
channel id validation now uses &str
1 parent 0e142f0 commit 687f3db

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

primitives/src/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ where
3232
D: Deserializer<'de>,
3333
{
3434
let channel_id = String::deserialize(deserializer)?;
35-
let channel_id = validate_channel_id(channel_id).map_err(serde::de::Error::custom)?;
35+
let channel_id = validate_channel_id(&channel_id).map_err(serde::de::Error::custom)?;
3636
<[u8; 32] as FromHex>::from_hex(channel_id).map_err(serde::de::Error::custom)
3737
}
3838

39-
fn validate_channel_id(s: String) -> Result<String, FromHexError> {
39+
fn validate_channel_id(s: &str) -> Result<&str, FromHexError> {
4040
if s.is_empty() || s.len() != 66 || &s[0..2] != "0x" {
4141
Err(FromHexError::InvalidStringLength)
4242
} else {
43-
Ok(s[2..].into())
43+
Ok(&s[2..])
4444
}
4545
}
4646

@@ -84,7 +84,7 @@ impl FromStr for ChannelId {
8484
type Err = FromHexError;
8585

8686
fn from_str(s: &str) -> Result<Self, Self::Err> {
87-
ChannelId::from_hex(validate_channel_id(s.into())?)
87+
ChannelId::from_hex(validate_channel_id(s)?)
8888
}
8989
}
9090

0 commit comments

Comments
 (0)