bstr
bstr copied to clipboard
Someday: implement `ByteSlice` for `[u8; N]` using const generics
In the distant future, when bstr can use const generics, the following reduces the amount of B(b"blah") you need to to literals do by a decent amount, letting you use ByteSlice methods directly on b"foo".
(Of course, you still need B for the &str literal case, e.g. B("😅") and such, but in practice that case isn't as bad, since as_bytes() also works)
impl<const N: usize> ByteSlice for [u8; N] {
#[inline]
fn as_bytes(&self) -> &[u8] {
self
}
#[inline]
fn as_bytes_mut(&mut self) -> &mut [u8] {
self
}
}
(Well, in practice you also need impl<const N: usize> Sealed for [u8; N] {}, but that's not important).
Nothing to do for now, but would be a nice thing to add when (or if, I guess) the MSRV gets to 1.51.
Oooooo yes, this would be lovely. I freaking hate B. :-)
This will likely motivate to bump the MSRV sooner than I would otherwise. I'll wait until it's at least been on stable for two release though.
Would now be a good time for this?
This is unblocked now that bstr 1.0 is out and MSRV is 1.60
PR for this is here:
- https://github.com/BurntSushi/bstr/pull/133
that was pretty painless!