feat(spansy): add AsRef<Span<[u8]>> impl for Span<str> (#20)

This commit is contained in:
sinu.eth
2024-02-08 10:28:15 -08:00
committed by GitHub
parent 7e1013e4f6
commit b1a3b01a30

View File

@@ -169,6 +169,16 @@ impl Span<str> {
}
}
impl AsRef<Span<[u8]>> for Span<str> {
fn as_ref(&self) -> &Span<[u8]> {
// # Safety
// Span<str> can be safely converted to Span<[u8]> because they have
// an identical layout and only differ in the phantom type parameter
// which is a ZST.
unsafe { &*(self as *const Span<str> as *const Span<[u8]>) }
}
}
impl AsRef<str> for Span<str> {
fn as_ref(&self) -> &str {
// # Safety