Skip to content

Commit

Permalink
Add optional borsh serialization/deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuuzetsu committed Nov 24, 2023
1 parent 5aaf742 commit 5ea75b3
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ __internal_bench = []

[dependencies]
serde = { version = "1.0.99", default-features = false, optional = true }
borsh = { version = "1.2", default-features = false, optional = true, features = ["derive"] }
pure-rust-locales = { version = "0.7", optional = true }
rkyv = { version = "0.7", optional = true }
arbitrary = { version = "1.0.0", features = ["derive"], optional = true }
Expand Down Expand Up @@ -58,7 +59,7 @@ bincode = { version = "1.3.0" }
wasm-bindgen-test = "0.3"

[package.metadata.docs.rs]
features = ["arbitrary, rkyv, serde, unstable-locales"]
features = ["arbitrary, rkyv, serde, unstable-locales, borsh"]
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
Expand Down
1 change: 1 addition & 0 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum SecondsFormat {
/// [`TimeZone`](./offset/trait.TimeZone.html) implementations.
#[derive(Clone)]
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 77 in src/datetime/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/datetime/mod.rs#L77

Added line #L77 was not covered by tests
pub struct DateTime<Tz: TimeZone> {
datetime: NaiveDateTime,
offset: Tz::Offset,
Expand Down
5 changes: 5 additions & 0 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ use crate::OutOfRange;
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshDeserialize, borsh::BorshSerialize),

Check warning on line 40 in src/month.rs

View check run for this annotation

Codecov / codecov/patch

src/month.rs#L40

Added line #L40 was not covered by tests
borsh(use_discriminant = true)
)]
pub enum Month {
/// January
January = 0,
Expand Down
1 change: 1 addition & 0 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl Days {
feature = "rkyv",
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 198 in src/naive/date.rs

View check run for this annotation

Codecov / codecov/patch

src/naive/date.rs#L198

Added line #L198 was not covered by tests
pub struct NaiveDate {
ymdf: DateImpl, // (year << 13) | of
}
Expand Down
1 change: 1 addition & 0 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub const MAX_DATETIME: NaiveDateTime = NaiveDateTime::MAX;
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 81 in src/naive/datetime/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/naive/datetime/mod.rs#L81

Added line #L81 was not covered by tests
pub struct NaiveDateTime {
date: NaiveDate,
time: NaiveTime,
Expand Down
1 change: 1 addition & 0 deletions src/naive/isoweek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rkyv::{Archive, Deserialize, Serialize};
feature = "rkyv",
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 25 in src/naive/isoweek.rs

View check run for this annotation

Codecov / codecov/patch

src/naive/isoweek.rs#L25

Added line #L25 was not covered by tests
pub struct IsoWeek {
// note that this allows for larger year range than `NaiveDate`.
// this is crucial because we have an edge case for the first and last week supported,
Expand Down
1 change: 1 addition & 0 deletions src/naive/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ mod tests;
feature = "rkyv",
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 207 in src/naive/time/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/naive/time/mod.rs#L207

Added line #L207 was not covered by tests
pub struct NaiveTime {
secs: u32,
frac: u32,
Expand Down
1 change: 1 addition & 0 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{NaiveDateTime, ParseError};
#[derive(PartialEq, Eq, Hash, Copy, Clone)]
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
#[cfg_attr(feature = "rkyv", archive_attr(derive(Clone, Copy, PartialEq, Eq, Hash, Debug)))]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 25 in src/offset/fixed.rs

View check run for this annotation

Codecov / codecov/patch

src/offset/fixed.rs#L25

Added line #L25 was not covered by tests
pub struct FixedOffset {
local_minus_utc: i32,
}
Expand Down
1 change: 1 addition & 0 deletions src/offset/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ mod tz_info;
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
#[cfg_attr(feature = "rkyv", archive_attr(derive(Clone, Copy, Debug)))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 107 in src/offset/local/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/offset/local/mod.rs#L107

Added line #L107 was not covered by tests
pub struct Local;

impl Local {
Expand Down
1 change: 1 addition & 0 deletions src/offset/utc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::DateTime;
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
#[cfg_attr(feature = "rkyv", archive_attr(derive(Clone, Copy, PartialEq, Eq, Debug, Hash)))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 46 in src/offset/utc.rs

View check run for this annotation

Codecov / codecov/patch

src/offset/utc.rs#L46

Added line #L46 was not covered by tests
pub struct Utc;

#[cfg(feature = "clock")]
Expand Down
1 change: 1 addition & 0 deletions src/time_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ macro_rules! try_opt {
feature = "rkyv",
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]

Check warning on line 59 in src/time_delta.rs

View check run for this annotation

Codecov / codecov/patch

src/time_delta.rs#L59

Added line #L59 was not covered by tests
pub struct TimeDelta {
secs: i64,
nanos: i32, // Always 0 <= nanos < NANOS_PER_SEC
Expand Down
5 changes: 5 additions & 0 deletions src/weekday.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ use crate::OutOfRange;
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
#[cfg_attr(feature = "rkyv", archive_attr(derive(Clone, Copy, PartialEq, Eq, Debug, Hash)))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshDeserialize, borsh::BorshSerialize),

Check warning on line 38 in src/weekday.rs

View check run for this annotation

Codecov / codecov/patch

src/weekday.rs#L38

Added line #L38 was not covered by tests
borsh(use_discriminant = true)
)]
pub enum Weekday {
/// Monday.
Mon = 0,
Expand Down

0 comments on commit 5ea75b3

Please sign in to comment.