diff --git a/Cargo.toml b/Cargo.toml index 2830bd4302..c08ea21f13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } @@ -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] diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 6efd15ef8c..7dd976a6a9 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -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))] pub struct DateTime { datetime: NaiveDateTime, offset: Tz::Offset, diff --git a/src/month.rs b/src/month.rs index acb96a2da1..987678fefa 100644 --- a/src/month.rs +++ b/src/month.rs @@ -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), + borsh(use_discriminant = true) +)] pub enum Month { /// January January = 0, diff --git a/src/naive/date.rs b/src/naive/date.rs index faccc06024..72e9781951 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -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))] pub struct NaiveDate { ymdf: DateImpl, // (year << 13) | of } diff --git a/src/naive/datetime/mod.rs b/src/naive/datetime/mod.rs index 3816be9c42..cb9295db87 100644 --- a/src/naive/datetime/mod.rs +++ b/src/naive/datetime/mod.rs @@ -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))] pub struct NaiveDateTime { date: NaiveDate, time: NaiveTime, diff --git a/src/naive/isoweek.rs b/src/naive/isoweek.rs index 606699659b..7532f5bfc9 100644 --- a/src/naive/isoweek.rs +++ b/src/naive/isoweek.rs @@ -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))] 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, diff --git a/src/naive/time/mod.rs b/src/naive/time/mod.rs index f2a0693ffd..c31d32849a 100644 --- a/src/naive/time/mod.rs +++ b/src/naive/time/mod.rs @@ -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))] pub struct NaiveTime { secs: u32, frac: u32, diff --git a/src/offset/fixed.rs b/src/offset/fixed.rs index 1c3dc5e366..67abc81391 100644 --- a/src/offset/fixed.rs +++ b/src/offset/fixed.rs @@ -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))] pub struct FixedOffset { local_minus_utc: i32, } diff --git a/src/offset/local/mod.rs b/src/offset/local/mod.rs index bc48b322e2..cecc761f55 100644 --- a/src/offset/local/mod.rs +++ b/src/offset/local/mod.rs @@ -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))] pub struct Local; impl Local { diff --git a/src/offset/utc.rs b/src/offset/utc.rs index e81949ec96..0d5f10d588 100644 --- a/src/offset/utc.rs +++ b/src/offset/utc.rs @@ -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))] pub struct Utc; #[cfg(feature = "clock")] diff --git a/src/time_delta.rs b/src/time_delta.rs index 84d049275a..0ee1f879c2 100644 --- a/src/time_delta.rs +++ b/src/time_delta.rs @@ -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))] pub struct TimeDelta { secs: i64, nanos: i32, // Always 0 <= nanos < NANOS_PER_SEC diff --git a/src/weekday.rs b/src/weekday.rs index a9c51069c4..2e6907bab7 100644 --- a/src/weekday.rs +++ b/src/weekday.rs @@ -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), + borsh(use_discriminant = true) +)] pub enum Weekday { /// Monday. Mon = 0,