From 5e82230b57a2699fdd0ad4d86b40c68621719c8b Mon Sep 17 00:00:00 2001 From: glorv Date: Fri, 18 Oct 2024 17:40:50 +0800 Subject: [PATCH] lossen the ToHex requirement to support unsized type --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bc6a69d..a220c62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,7 +134,7 @@ fn encode_to_iter>(table: &'static [u8; 16], source: BytesToHexChars::new(source, table).collect() } -impl> ToHex for T { +impl + ?Sized> ToHex for T { fn encode_hex>(&self) -> U { encode_to_iter(HEX_CHARS_LOWER, self.as_ref()) } @@ -539,5 +539,12 @@ mod test { [0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72].encode_hex_upper::(), "666F6F626172".to_string(), ); + + // test for unsize type. + let s = &[0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]; + assert_eq!( + <[u8]>::encode_hex::(s), + "666f6f626172".to_string(), + ); } }