mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(rlp): add encode for &str (#147)
* feat(rlp): add encode for &str * add test
This commit is contained in:
@ -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")[..]);
|
||||
|
||||
Reference in New Issue
Block a user