Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Someday: implement ByteSlice for [u8; N] using const generics #86

Closed
thomcc opened this issue Apr 13, 2021 · 4 comments · Fixed by #133
Closed

Someday: implement ByteSlice for [u8; N] using const generics #86

thomcc opened this issue Apr 13, 2021 · 4 comments · Fixed by #133
Labels
enhancement New feature or request

Comments

@thomcc
Copy link
Contributor

thomcc commented Apr 13, 2021

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.

@BurntSushi
Copy link
Owner

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.

@Cyborus04
Copy link

Would now be a good time for this?

@lopopolo
Copy link
Contributor

This is unblocked now that bstr 1.0 is out and MSRV is 1.60

lopopolo added a commit to lopopolo/bstr that referenced this issue Sep 14, 2022
@lopopolo
Copy link
Contributor

PR for this is here:

that was pretty painless!

BurntSushi pushed a commit that referenced this issue Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants