Skip to content

Commit

Permalink
support tagged/authed pointers after union change + bytes v1.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLuq committed Aug 3, 2024
1 parent fe2a7c2 commit 2f1e72c
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 290 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = ["TimLuq"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bytes_1 = { package = "bytes", version = "^1.6.1", optional = true, default-features = false }
bytes_1 = { package = "bytes", version = "^1.7.1", optional = true, default-features = false }
http-body_04 = { package = "http-body", version = "0.4.5", optional = true }
http-body_1 = { package = "http-body", version = "1", optional = true }
http_02 = { package = "http", version = "0.2.4", optional = true }
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

A library for working with byte slices in a `const`-friendly manner.

Provides the main types `ByteData` and `StringData` which are wrappers around byte sequences and string sequences respectively.

When the `alloc` feature is enabled this crate provides `SharedBytes` which operates like `Arc<[u8]>` but with a representation that allows for `const` references to the bytes and zero-copy subslicing.
The `SharedBytes` type is then also added as one additional representation of `ByteData`.

Expand All @@ -10,11 +12,13 @@ The `SharedBytes` type is then also added as one additional representation of `B
### alloc

Enables runtime allocation of byte arrays on the heap.
This allows for dynamic allocation of byte arrays which are exposed as `SharedBytes` and can be wrapped as `ByteData::Shared(_)`.
This allows for dynamic allocation of byte arrays which are exposed as `SharedBytes` and can be wrapped using `ByteData::from_shared`.

### chunk

Enables runtime representation of small byte arrays inline as `ByteData::Chunk(_)`.
This feature is now built-in and activating it does nothing.

Previously enabled runtime representation of small byte arrays inline as `ByteChunk` which is one representation of `ByteData`.
This allows for optimized storage of small byte arrays that are less than or equal to 14 bytes in size.

### macros
Expand All @@ -25,17 +29,17 @@ These macros allow for concatenation of static byte arrays and strings that are

### bytes_1

Enables integration with the `bytes` crate (version `>=1.6.1, <2`).
Enables integration with the `bytes` crate (version `>=1.7.1, <2`).
This allows for conversion between `SharedBytes` and `bytes::Bytes` types.
Where possible no bytes will be cloned, which means that `ByteData::Static(_)` will map to `bytes::Bytes::from_static`,
Where possible no bytes will be cloned, which means that `ByteData::from_static` will map to `bytes::Bytes::from_static`,
and that `<bytes::Bytes as From<SharedBytes>>::from` will return a `bytes::Bytes` object that is just a wrapper and still share the bytes as normal without any copying.

There is, however, a possibility that the internal vtable or structure of `bytes::Bytes` changes in the future, in which case the zero-copy may break or segfault.
There is, however, a possibility that the internal vtable or structure of `bytes::Bytes` changes in the future or results in a different ordered ABI, in which case the zero-copy may break or segfault.
If this happens you can enable the feature `bytes_1_safe` which will always cause the bytes to be cloned when converting to and from `bytes::Bytes` without the use of any internal structures.

### bytes_1_safe

Enables integration with the `bytes` crate (version `>=1.6.1, <2`) in a safe manner.
Enables integration with the `bytes` crate (version `>=1.7.1, <2`) in a safe manner.
This will cause the bytes to always be cloned when converting to and from `bytes::Bytes`.

For zero-copy conversion between `SharedBytes` and `bytes::Bytes`, use the `bytes_1` feature instead - unless it is broken.
Expand All @@ -54,7 +58,7 @@ The trait `http_body::Body` is then implemented for `ByteData` and `SharedBytes`

### queue

Enables the `ByteQueue` type which is a queue of `ByteData` objects that can be pushed to and popped from.
Enables the `ByteQueue`/`StringQueue` types which are queues of `ByteData`/`StringData` objects that can be pushed to and popped from.
Unless the `alloc` feature is enabled, the queue will be limited to a maximum size of 8 elements.

### nom_7
Expand Down
1 change: 0 additions & 1 deletion src/byte_chunk.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::{ops::RangeBounds, slice::SliceIndex};

/// A chunk of bytes that is 14 bytes or less.
#[cfg_attr(docsrs, doc(cfg(feature = "chunk")))]
#[derive(Clone, Copy)]
pub struct ByteChunk {
/// The length of the chunk.
Expand Down
Loading

0 comments on commit 2f1e72c

Please sign in to comment.