Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/.hegel/
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
<!-- next-header -->
## Unreleased - ReleaseDate

### Added

- `Base64Slice`, the borrowed counterpart of `Base64Vec`, analogous to `str`
and `String`.

### Changed

- **Breaking:** `Base64Vec` now dereferences to `Base64Slice` instead of
`Vec<u8>`, and no longer implements `DerefMut`. `Base64Slice` dereferences
to `[u8]`, so slice methods such as `len` and indexing still work. To modify
the bytes, use the public field (`.0`) or `AsMut<[u8]>`.
- **Breaking:** The `base64` feature no longer implies `alloc`. `Base64Slice`
is now available without `alloc`, but `Base64Vec` and `ParseBase64Error`
require both `base64` and `alloc`. `alloc` is enabled by default; if you use
`default-features = false` with `features = ["base64"]`, add `"alloc"` to keep
`Base64Vec`.
- `Base64Slice` and `Base64Vec` now format with `Display` and `Debug` without
allocating an intermediate `String`.

### Fixed

- `Base64Vec` can now be deserialized from CBOR byte strings longer than 4096
Expand Down
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ pre-release-replacements = [
]

[features]
default = ["base64", "hex"]
alloc = ["serde_core?/alloc"]
base64 = ["alloc", "dep:base64"]
default = ["alloc", "base64", "hex"]
alloc = ["base64?/alloc", "serde_core?/alloc"]
base64 = ["dep:base64"]
hex = ["dep:hex"]
schemars08 = ["alloc", "dep:schemars08", "dep:serde_json"]
serde = ["dep:serde_core"]

[dependencies]
base64 = { version = "0.23", default-features = false, features = ["alloc"], optional = true }
base64 = { version = "0.23", default-features = false, optional = true }
hex = { version = "0.4", default-features = false, optional = true }
schemars08 = { package = "schemars", version = "0.8", optional = true }
serde_core = { version = "1", default-features = false, optional = true }
Expand All @@ -61,6 +61,7 @@ serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = "1"
ciborium = "0.2"
expectorate = "1"
hegeltest = "0.46.4"
prettyplease = "0.2"
quote = "1"
syn = "2"
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ human-readable encodings. [`HexArray<N>`] encodes fixed-length byte
arrays as hex strings, and [`Base64Vec`] encodes variable-length
byte vectors as base64 strings.

With the `serde` feature, both types implement `Serialize` and
With the `serde` feature, this crate’s types implement `Serialize` and
`Deserialize`, encoding as human-readable strings (hex or base64) in text
formats like JSON, and as efficient raw bytes in binary formats like [CBOR].
You do not have to use the newtypes in your own type definitions; you can
refer to them via `#[serde(with = "...")]` instead.

With the `schemars08` feature, both types implement [`JsonSchema`],
With the `schemars08` feature, this crate’s types implement [`JsonSchema`],
including automatic opt-in replacement with
[typify](https://crates.io/crates/typify) and
[progenitor](https://crates.io/crates/progenitor).
Expand All @@ -34,7 +34,9 @@ including automatic opt-in replacement with
* [`HexArray<N>`] encodes a fixed-length byte array as a hex
string. (Requires the `hex` feature.)
* [`Base64Vec`] encodes a variable-length byte vector as a base64
string. (Requires the `base64` feature.)
string. (Requires the `base64` and `alloc` features.)
* [`Base64Slice`] encodes a borrowed byte slice as a base64 string.
(Requires the `base64` feature.)

## Examples

Expand Down Expand Up @@ -107,9 +109,10 @@ The closest alternatives are:
## Features

* **`hex`**: enables [`HexArray`]. *Enabled by default.*
* **`base64`**: enables [`Base64Vec`] (implies `alloc`).
* **`base64`**: enables [`Base64Slice`], and [`Base64Vec`] together with
`alloc`. *Enabled by default.*
* **`alloc`**: enables `alloc` support (required by [`Base64Vec`]).
*Enabled by default.*
* **`alloc`**: enables `alloc` support (required by `base64`).
* **`serde`**: implements `Serialize` and `Deserialize` for
enabled types. *Not enabled by default.*
* **`schemars08`**: derives `JsonSchema` for enabled types.
Expand All @@ -121,6 +124,7 @@ All features other than `schemars08` are compatible with `no_std`.
[`Base64Vec`]: https://docs.rs/byte-wrapper/0.1.1/byte_wrapper/base64_vec/struct.Base64Vec.html "struct byte_wrapper::base64_vec::Base64Vec"
[CBOR]: https://cbor.io/
[`JsonSchema`]: https://docs.rs/schemars/0.8/schemars/trait.JsonSchema.html
[`Base64Slice`]: https://docs.rs/byte-wrapper/0.1.1/byte_wrapper/base64_slice/struct.Base64Slice.html "struct byte_wrapper::base64_slice::Base64Slice"
[`serde-human-bytes`]: https://docs.rs/serde-human-bytes
[`serde-encoded-bytes`]: https://docs.rs/serde-encoded-bytes
[`serde_with`]: https://docs.rs/serde_with
Expand Down
Loading
Loading