Skip to content
Open
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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ now = []
serde = ["dep:serde"]
# Note that rkyv-16, rkyv-32, and rkyv-64 are mutually exclusive.
# Enable serialization/deserialization via rkyv, using 16-bit integers for integral `*size` types.
rkyv-16 = ["dep:rkyv", "rkyv?/size_16"]
rkyv-16 = ["dep:rkyv", "rkyv?/pointer_width_16"]
# Enable serialization/deserialization via rkyv, using 32-bit integers for integral `*size` types.
rkyv-32 = ["dep:rkyv", "rkyv?/size_32"]
rkyv-32 = ["dep:rkyv", "rkyv?/pointer_width_32"]
# Enable serialization/deserialization via rkyv, using 64-bit integers for integral `*size` types.
rkyv-64 = ["dep:rkyv", "rkyv?/size_64"]
rkyv-64 = ["dep:rkyv", "rkyv?/pointer_width_64"]
# Enable rkyv validation support using `bytecheck`.
rkyv-validation = ["dep:rkyv", "rkyv?/validation"]
rkyv-validation = ["dep:rkyv", "rkyv?/bytecheck"]
# Construct arbitrary instances of a type with the arbitrary crate.
arbitrary = ["dep:arbitrary"]
# Interface with the JS Date API for the `wasm32` target.
Expand All @@ -52,7 +52,7 @@ unstable-locales = ["dep:pure-rust-locales"]
[dependencies]
serde = { version = "1.0.99", default-features = false, optional = true }
pure-rust-locales = { version = "0.8", optional = true }
rkyv = { version = "0.7.43", default-features = false, optional = true }
rkyv = { version = "0.8.10", optional = true }
arbitrary = { version = "1.0.0", features = ["derive"], optional = true }

[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
Expand Down
3 changes: 1 addition & 2 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ mod tests;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq, PartialOrd))
rkyv(compare(PartialEq, PartialOrd))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
pub struct DateTime<Tz: TimeZone> {
datetime: NaiveDateTime,
offset: Tz::Offset,
Expand Down
9 changes: 4 additions & 5 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ use crate::OutOfRange;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq, PartialOrd)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
rkyv(compare(PartialEq, PartialOrd)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(arbitrary::Arbitrary))]
pub enum Month {
/// January
Expand Down Expand Up @@ -356,7 +355,7 @@ mod tests {
#[cfg(feature = "rkyv-validation")]
fn test_rkyv_validation() {
let month = Month::January;
let bytes = rkyv::to_bytes::<_, 1>(&month).unwrap();
assert_eq!(rkyv::from_bytes::<Month>(&bytes).unwrap(), month);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&month).unwrap();
assert_eq!(rkyv::from_bytes::<Month, rkyv::rancor::Error>(&bytes).unwrap(), month);
}
}
5 changes: 2 additions & 3 deletions src/naive/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ mod tests;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq, PartialOrd)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
rkyv(compare(PartialEq, PartialOrd)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
pub struct NaiveDate {
yof: NonZeroI32, // (year << 13) | of
}
Expand Down
8 changes: 4 additions & 4 deletions src/naive/date/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,12 +773,12 @@ const YEAR_FLAGS: [(i32, YearFlags, Weekday); 14] = [
#[cfg(feature = "rkyv-validation")]
fn test_rkyv_validation() {
let date_min = NaiveDate::MIN;
let bytes = rkyv::to_bytes::<_, 4>(&date_min).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveDate>(&bytes).unwrap(), date_min);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&date_min).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveDate, rkyv::rancor::Error>(&bytes).unwrap(), date_min);

let date_max = NaiveDate::MAX;
let bytes = rkyv::to_bytes::<_, 4>(&date_max).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveDate>(&bytes).unwrap(), date_max);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&date_max).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveDate, rkyv::rancor::Error>(&bytes).unwrap(), date_max);
}

// MAX_YEAR-12-31 minus 0000-01-01
Expand Down
5 changes: 2 additions & 3 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ mod tests;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq, PartialOrd)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
rkyv(compare(PartialEq, PartialOrd)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(arbitrary::Arbitrary))]
pub struct NaiveDateTime {
date: NaiveDate,
Expand Down
8 changes: 4 additions & 4 deletions src/naive/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ fn test_and_timezone_min_max_dates() {
#[cfg(feature = "rkyv-validation")]
fn test_rkyv_validation() {
let dt_min = NaiveDateTime::MIN;
let bytes = rkyv::to_bytes::<_, 12>(&dt_min).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveDateTime>(&bytes).unwrap(), dt_min);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&dt_min).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveDateTime, rkyv::rancor::Error>(&bytes).unwrap(), dt_min);

let dt_max = NaiveDateTime::MAX;
let bytes = rkyv::to_bytes::<_, 12>(&dt_max).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveDateTime>(&bytes).unwrap(), dt_max);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&dt_max).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveDateTime, rkyv::rancor::Error>(&bytes).unwrap(), dt_max);
}
13 changes: 6 additions & 7 deletions src/naive/isoweek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use rkyv::{Archive, Deserialize, Serialize};
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq, PartialOrd)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
rkyv(compare(PartialEq, PartialOrd)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
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 Expand Up @@ -217,11 +216,11 @@ mod tests {
#[cfg(feature = "rkyv-validation")]
fn test_rkyv_validation() {
let minweek = NaiveDate::MIN.iso_week();
let bytes = rkyv::to_bytes::<_, 4>(&minweek).unwrap();
assert_eq!(rkyv::from_bytes::<IsoWeek>(&bytes).unwrap(), minweek);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&minweek).unwrap();
assert_eq!(rkyv::from_bytes::<IsoWeek, rkyv::rancor::Error>(&bytes).unwrap(), minweek);

let maxweek = NaiveDate::MAX.iso_week();
let bytes = rkyv::to_bytes::<_, 4>(&maxweek).unwrap();
assert_eq!(rkyv::from_bytes::<IsoWeek>(&bytes).unwrap(), maxweek);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&maxweek).unwrap();
assert_eq!(rkyv::from_bytes::<IsoWeek, rkyv::rancor::Error>(&bytes).unwrap(), maxweek);
}
}
5 changes: 2 additions & 3 deletions src/naive/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,9 @@ mod tests;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq, PartialOrd)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
rkyv(compare(PartialEq, PartialOrd)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
pub struct NaiveTime {
secs: u32,
frac: u32,
Expand Down
8 changes: 4 additions & 4 deletions src/naive/time/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ fn test_overflowing_offset() {
#[cfg(feature = "rkyv-validation")]
fn test_rkyv_validation() {
let t_min = NaiveTime::MIN;
let bytes = rkyv::to_bytes::<_, 8>(&t_min).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveTime>(&bytes).unwrap(), t_min);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&t_min).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveTime, rkyv::rancor::Error>(&bytes).unwrap(), t_min);

let t_max = NaiveTime::MAX;
let bytes = rkyv::to_bytes::<_, 8>(&t_max).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveTime>(&bytes).unwrap(), t_max);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&t_max).unwrap();
assert_eq!(rkyv::from_bytes::<NaiveTime, rkyv::rancor::Error>(&bytes).unwrap(), t_max);
}
9 changes: 4 additions & 5 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ use crate::{Error, NaiveDateTime, ParseError};
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, Hash, Debug))
rkyv(compare(PartialEq)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, Hash, Debug)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
pub struct FixedOffset {
local_minus_utc: i32,
}
Expand Down Expand Up @@ -202,7 +201,7 @@ mod tests {
#[cfg(feature = "rkyv-validation")]
fn test_rkyv_validation() {
let offset = FixedOffset::from_str("-0500").unwrap();
let bytes = rkyv::to_bytes::<_, 4>(&offset).unwrap();
assert_eq!(rkyv::from_bytes::<FixedOffset>(&bytes).unwrap(), offset);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&offset).unwrap();
assert_eq!(rkyv::from_bytes::<FixedOffset, rkyv::rancor::Error>(&bytes).unwrap(), offset);
}
}
12 changes: 7 additions & 5 deletions src/offset/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ mod tz_info;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq)),
archive_attr(derive(Clone, Copy, Debug))
rkyv(compare(PartialEq)),
rkyv(attr(derive(Clone, Copy, Debug)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct Local;

Expand Down Expand Up @@ -516,11 +515,14 @@ mod tests {
fn test_rkyv_validation() {
let local = Local;
// Local is a ZST and serializes to 0 bytes
let bytes = rkyv::to_bytes::<_, 0>(&local).unwrap();
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&local).unwrap();
assert_eq!(bytes.len(), 0);

// but is deserialized to an archived variant without a
// wrapping object
assert_eq!(rkyv::from_bytes::<Local>(&bytes).unwrap(), super::ArchivedLocal);
assert_eq!(
rkyv::from_bytes::<Local, rkyv::rancor::Error>(&bytes).unwrap(),
super::ArchivedLocal
);
}
}
5 changes: 2 additions & 3 deletions src/offset/utc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ use crate::OutOfRange;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, Debug, Hash))
rkyv(compare(PartialEq)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, Debug, Hash)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(arbitrary::Arbitrary))]
pub struct Utc;

Expand Down
9 changes: 4 additions & 5 deletions src/time_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ const SECS_PER_WEEK: i64 = 604_800;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq, PartialOrd)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
rkyv(compare(PartialEq, PartialOrd)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
pub struct TimeDelta {
secs: i64,
nanos: i32, // Always 0 <= nanos < NANOS_PER_SEC
Expand Down Expand Up @@ -1058,7 +1057,7 @@ mod tests {
#[cfg(feature = "rkyv-validation")]
fn test_rkyv_validation() {
let duration = TimeDelta::seconds(1);
let bytes = rkyv::to_bytes::<_, 16>(&duration).unwrap();
assert_eq!(rkyv::from_bytes::<TimeDelta>(&bytes).unwrap(), duration);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&duration).unwrap();
assert_eq!(rkyv::from_bytes::<TimeDelta, rkyv::rancor::Error>(&bytes).unwrap(), duration);
}
}
9 changes: 4 additions & 5 deletions src/weekday.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ use crate::OutOfRange;
#[cfg_attr(
any(feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, Debug, Hash))
rkyv(compare(PartialEq)),
rkyv(attr(derive(Clone, Copy, PartialEq, Eq, Debug, Hash)))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(arbitrary::Arbitrary))]
pub enum Weekday {
/// Monday.
Expand Down Expand Up @@ -358,8 +357,8 @@ mod tests {
#[cfg(feature = "rkyv-validation")]
fn test_rkyv_validation() {
let mon = Weekday::Mon;
let bytes = rkyv::to_bytes::<_, 1>(&mon).unwrap();
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&mon).unwrap();

assert_eq!(rkyv::from_bytes::<Weekday>(&bytes).unwrap(), mon);
assert_eq!(rkyv::from_bytes::<Weekday, rkyv::rancor::Error>(&bytes).unwrap(), mon);
}
}
Loading