Skip to content

Commit

Permalink
fix: introduce codec feature flag (#30)
Browse files Browse the repository at this point in the history
Implementing the `Codec` trait needs at least Rust version 1.75. This commit
introduces a feature flag, so that lower versions of Rust can be supported,
in case the `Codec` trait implementation is not needed.
  • Loading branch information
vmx committed Mar 26, 2024
1 parent feb21ee commit 76f1999
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ edition = "2018"

[dependencies]
cbor4ii = { version = "0.2.14", default-features = false, features = ["use_alloc"] }
ipld-core = { version = "0.3.2", default-features = false, features = ["serde"] }
ipld-core = { version = "0.4.0", default-features = false, features = ["serde"] }
scopeguard = "1.1.0"
serde = { version = "1.0.164", default-features = false, features = ["alloc"] }

Expand All @@ -26,7 +26,9 @@ serde_bytes = { version = "0.11.9", default-features = false, features = ["alloc
serde-transcode = "1.1.1"

[features]
default = ["std"]
default = ["codec", "std"]
std = ["cbor4ii/use_std", "ipld-core/std", "serde/std", "serde_bytes/std"]
# Enable the `Codec` trait implementation. It's a separate feature as it needs Rust >= 1.75.
codec = ["ipld-core/codec"]
# Prevent deserializing CIDs as bytes as much as possible.
no-cid-as-bytes = []
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ fn main() -> Result<(), Box<dyn Error>> {
Features
--------

### `codec`

The `codec` feature is enabled by default, it provides the `Codec` trait, which enables encoding and decoding independent of the IPLD Codec. The minimum supported Rust version (MSRV) can significantly be reduced to 1.64 by disabling this feature.


### `no-cid-as-bytes`

Sometimes it is desired that a CID is not accidentally deserialized into bytes. This can happen because the intermediate serde data model does not retain enough information to be able to differentiate between a bytes container and a CID container when there is a conflicting choice to be made, as in the case of some enum cases. The `no-cid-as-bytes` feature can be enabled in order to error at runtime in such cases.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ extern crate alloc;
mod cbor4ii_nonpub;
// The `Codec` implementation is only available if the `no-cid-as-bytes` feature is disabled, due
// to the links being extracted with a Serde based approach.
#[cfg(all(feature = "std", not(feature = "no-cid-as-bytes")))]
#[cfg(all(feature = "std", not(feature = "no-cid-as-bytes"), feature = "codec"))]
pub mod codec;
pub mod de;
pub mod error;
Expand Down

0 comments on commit 76f1999

Please sign in to comment.