Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(serde): borsh #42

Merged
merged 3 commits into from
Jul 3, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
- name: Install latest stable Rust
run: rustup install stable
- name: Check crate builds on stable
run: cargo build --features serde,numtraits,rand,arbitrary && cargo build
# NOTE: consider using https://github.com/frewsxcv/cargo-all-features, because all features != their arbitrary combinations
run: cargo build --features serde,numtraits,rand,arbitrary,borsh && cargo build
test_nightly:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ default = []
nightly = []
serde = ["dep:serde", "serde-big-array"]
numtraits = ["num-integer", "num-traits"]
borsh = ["dep:borsh"]

[dependencies]
num-integer = { version = "0.1", optional = true, default-features = false }
Expand All @@ -33,6 +34,7 @@ quickcheck = { version = "1.0", optional = true, default-features = false }
# proptest = { version = "1.2", optional = true, default-features = false }
valuable = { version = "0.1", optional = true, features = ["derive"], default-features = false }
# lit-parser = { path = "./lit-parser/", optional = true }
borsh = { version = "^1.5", optional = true, default-features = false, features = ["rc", "std", "unstable__schema"]}

[dev-dependencies]
quickcheck = "1.0"
Expand Down
7 changes: 7 additions & 0 deletions src/bint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ use crate::{doc, errors};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[cfg(feature = "borsh")]
use ::{
alloc::string::ToString,
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
};

use core::default::Default;

use core::iter::{Iterator, Product, Sum};
Expand All @@ -46,6 +52,7 @@ macro_rules! mod_impl {

#[derive(Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize, BorshSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "valuable", derive(valuable::Valuable))]
#[repr(transparent)]
Expand Down
7 changes: 7 additions & 0 deletions src/buint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ use ::{
serde_big_array::BigArray,
};

#[cfg(feature = "borsh")]
use ::{
alloc::string::ToString,
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
};

use core::default::Default;

use core::iter::{Iterator, Product, Sum};
Expand All @@ -29,6 +35,7 @@ macro_rules! mod_impl {

#[derive(Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize, BorshSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "valuable", derive(valuable::Valuable))]
#[repr(transparent)]
Expand Down