diff --git a/crates/common/rlp/src/encode.rs b/crates/common/rlp/src/encode.rs index a13feb00f..20839db28 100644 --- a/crates/common/rlp/src/encode.rs +++ b/crates/common/rlp/src/encode.rs @@ -291,6 +291,16 @@ mod alloc_support { } } } + +impl Encodable for &str { + fn encode(&self, out: &mut dyn BufMut) { + self.as_bytes().encode(out); + } + fn length(&self) -> usize { + self.as_bytes().length() + } +} + slice_impl!(Bytes); slice_impl!(BytesMut); @@ -369,6 +379,13 @@ mod tests { out1 } + #[test] + fn rlp_str() { + assert_eq!(encoded("")[..], hex!("80")[..]); + assert_eq!(encoded("{")[..], hex!("7b")[..]); + assert_eq!(encoded("test str")[..], hex!("887465737420737472")[..]); + } + #[test] fn rlp_strings() { assert_eq!(encoded(hex!(""))[..], hex!("80")[..]);