tokio-rs / bytes

Utilities for working with bytes
MIT License
1.86k stars 278 forks source link

feat: support From<&[u8; N]> for Bytes #683

Closed cjwcommuny closed 5 months ago

braddunbar commented 5 months ago

Hey @cjwcommuny! Out of curiosity, are you having an issue using Bytes::copy_from_slice directly or is this about the convenience of calling from/into?

cjwcommuny commented 5 months ago

@braddunbar I would like to write a function like:

fn foo(x: impl Into<Bytes>) {}

foo(b"hello");
foo(Bytes::new());

I believe that implementing <&[u8; N]> for Bytes would improve the ergonomics.

cjwcommuny commented 5 months ago

Hmmm... It seems that the "const generics" requires Rust 1.51+...

Darksonn commented 5 months ago

Due to the const generics issue, we are unlikely to add this feature at this time.