Skip to content

Commit cda9ef6

Browse files
glorvKokaKiwi
authored andcommitted
lossen the ToHex requirement to support unsized type
1 parent b3cd973 commit cda9ef6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn encode_to_iter<T: iter::FromIterator<char>>(table: &'static [u8; 16], source:
129129
BytesToHexChars::new(source, table).collect()
130130
}
131131

132-
impl<T: AsRef<[u8]>> ToHex for T {
132+
impl<T: AsRef<[u8]> + ?Sized> ToHex for T {
133133
fn encode_hex<U: iter::FromIterator<char>>(&self) -> U {
134134
encode_to_iter(HEX_CHARS_LOWER, self.as_ref())
135135
}
@@ -504,5 +504,12 @@ mod test {
504504
[0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72].encode_hex_upper::<String>(),
505505
"666F6F626172",
506506
);
507+
508+
// test for unsize type.
509+
let s = &[0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72];
510+
assert_eq!(
511+
<[u8]>::encode_hex::<String>(s),
512+
"666f6f626172".to_string(),
513+
);
507514
}
508515
}

0 commit comments

Comments
 (0)