-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
325: Bytes const size borrowed arrays r=jonasbb a=matix2267 Currently `Bytes` (added in #277) supports some const size array types (e.g. `[u8; N]` and `Box<[u8; N]>`) but not others (e.g. `&[u8; N]` and `Cow<'_, [u8; N]>`). This pull request implements `Bytes` support for `&[u8; N]` and `Cow<'_, [u8; N]>` This bring parity between dynamic and const sized types. ### Before: | Sizing | Owned | Borrowed | Cow | Box | | ------- | -------------- | ------------- | --------------------- | ----------------- | | Const | ✅ `[u8; N]` | ❌ `&[u8; N]` | ❌ `Cow<'_, [u8; N]>` | ✅ `Box<[u8; N]>` | | Dynamic | ✅ `Vec<u8>`\* | ✅ `&[u8]` | ✅ `Cow<'_, [u8]>` | ✅ `Box<[u8]>` | ### After: | Sizing | Owned | Borrowed | Cow | Box | | ------- | -------------- | ------------- | --------------------- | ----------------- | | Const | ✅ `[u8; N]` | ✅ `&[u8; N]` | ✅ `Cow<'_, [u8; N]>` | ✅ `Box<[u8; N]>` | | Dynamic | ✅ `Vec<u8>`\* | ✅ `&[u8]` | ✅ `Cow<'_, [u8]>` | ✅ `Box<[u8]>` | I've also added a separate commit with an example of using fully borrowed types, but that example only does serialization because RON doesn't support 0-copy deserialization for byte arrays (as it needs to decode them from base64). Because of that I'm not sure if this example is useful so feel free to merge only the main commit. <sub>\* Technically `[u8]` corresponds to `[u8; N]` but `[u8]` is an un`Sized` type and cannot be directly used in structs.</sub> Co-authored-by: matix2267 <matix2267@gmail.com>
- Loading branch information
Showing
4 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters