Skip to content

Commit

Permalink
Yus
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Nov 29, 2024
1 parent c1e4baa commit 47a5752
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 225 deletions.
2 changes: 1 addition & 1 deletion .zed/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"command": "clippy"
},
"cargo": {
"features": ["merde/full", "merde_core/full", "merde_time/full", "merde_json/full"]
"features": ["merde/full", "merde_core/full", "merde_json/full"]
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ resolver = "2"
members = [
"merde",
"merde_json",
"merde_time",
"merde_core",
"merde_yaml",
"merde_msgpack",
Expand Down
12 changes: 5 additions & 7 deletions merde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,13 @@ merde_core = { version = "8.1.1", path = "../merde_core", optional = true }
merde_json = { version = "8.0.2", path = "../merde_json", optional = true }
merde_yaml = { version = "8.0.2", path = "../merde_yaml", optional = true }
merde_msgpack = { version = "8.0.2", path = "../merde_msgpack", optional = true }
merde_time = { version = "8.0.3", path = "../merde_time", optional = true, features = [
"merde",
"serialize",
"deserialize",
] }
ahash = { version = "0.8.11", optional = true }

[features]
default = ["core", "deserialize"]
default = ["core"]
full = [
"core",
"serialize",
"deserialize",
"json",
"yaml",
Expand All @@ -79,16 +75,18 @@ full = [
"rusqlite",
]
core = ["dep:merde_core"]
serialize = ["core"]
deserialize = ["core"]

# merde_core re-exports
serde = ["merde_core/serde"]
rusqlite = ["merde_core/rusqlite"]
time = ["merde_core/time"]

# non-core crates
json = ["dep:merde_json"]
yaml = ["dep:merde_yaml"]
msgpack = ["dep:merde_msgpack"]
time = ["dep:merde_time"]

# others
ahash = ["dep:ahash"]
6 changes: 6 additions & 0 deletions merde_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ rubicon = "3.4.9"
rusqlite = { version = "0.32.1", optional = true }
serde = { version = "1", optional = true }
pin-project-lite = "0.2.15"
time = { version = "0.3.36", optional = true, features = ["parsing", "formatting"] }

[features]
default = []
full = [
# (1 per line)
"serde",
"rusqlite",
"time",
]
# Add `serde` implementations for merde_core types
serde = ["dep:serde", "compact_str/serde"]
# Add `merde` implementations for types of the `time` crate
time = ["dep:time"]
# Add `merde` implementations for types of the `rusqlite` crate
rusqlite = ["dep:rusqlite"]

[dev-dependencies]
Expand Down
8 changes: 3 additions & 5 deletions merde_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ and `CowStr<'s>` (a copy-on-write string type that also leverages
[compact_str](https://crates.io/crates/compact_str)'s small string
optimization), and traits like `Deserialize` and `IntoStatic`.

Crates that provide support for formats (like [merde_json](https://crates.io/crates/merde_json)),
and crates that provide wrappers around other crates' types, to allow serializing/deserializing
them (like [merde_time](https://crates.io/crates/merde_time)), depend only on the "core" crate.
Crates that provide support for formats (like [merde_json](https://crates.io/crates/merde_json)), depend only on the "core" crate.

The umbrella crate [merde](https://crates.io/crates/merde) re-exports core's types, along
with a `derive!` macro which lets you implement `ValueDeserialize`, `IntoStatic`, and format-specific
traits like `JsonSerialize` on structs, with or without lifetime parameters.
with a `derive!` macro which lets you implement `Serialize`, `Deserialize`, `IntoStatic`,
on structs, enums, etc.
3 changes: 3 additions & 0 deletions merde_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub use deserialize::DeserializeOwned;
pub use deserialize::Deserializer;
pub use deserialize::FieldSlot;

mod rfc3339;
pub use rfc3339::Rfc3339;

rubicon::compatibility_check! {
("merde_core_pkg_version", env!("CARGO_PKG_VERSION")),
}
27 changes: 12 additions & 15 deletions merde_time/src/lib.rs → merde_core/src/rfc3339.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! Provides [Rfc3339], a wrapper around [time::OffsetDateTime] that implements
//! [merde_core::Serialize] and [merde_core::Deserialize] when the right
//! [Serialize] and [Deserialize] when the right
//! cargo features are enabled.

use std::{
fmt,
ops::{Deref, DerefMut},
};

pub use time::OffsetDateTime;

/// A wrapper around date-time types that implements `Serialize` and `Deserialize`
/// when the right cargo features are enabled.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -53,47 +51,46 @@ where
}
}

#[cfg(feature = "merde")]
mod merde_impls {
#[cfg(feature = "time")]
mod time_impls {
use super::*;

impl merde_core::IntoStatic for Rfc3339<OffsetDateTime> {
use time::OffsetDateTime;
impl crate::IntoStatic for Rfc3339<OffsetDateTime> {
type Output = Rfc3339<OffsetDateTime>;

fn into_static(self) -> Self::Output {
self
}
}

#[cfg(feature = "deserialize")]
impl<'s> merde_core::Deserialize<'s> for Rfc3339<time::OffsetDateTime> {
impl<'s> crate::Deserialize<'s> for Rfc3339<time::OffsetDateTime> {
async fn deserialize<D>(de: &mut D) -> Result<Self, D::Error<'s>>
where
D: merde_core::Deserializer<'s> + ?Sized,
D: crate::Deserializer<'s> + ?Sized,
{
let s = merde_core::CowStr::deserialize(de).await?;
let s = crate::CowStr::deserialize(de).await?;
Ok(Rfc3339(
time::OffsetDateTime::parse(
s.as_ref(),
&time::format_description::well_known::Rfc3339,
)
.map_err(|_| merde_core::MerdeError::InvalidDateTimeValue)?,
.map_err(|_| crate::MerdeError::InvalidDateTimeValue)?,
))
}
}

#[cfg(feature = "serialize")]
impl merde_core::Serialize for Rfc3339<time::OffsetDateTime> {
impl crate::Serialize for Rfc3339<time::OffsetDateTime> {
async fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where
S: merde_core::Serializer + ?Sized,
S: crate::Serializer + ?Sized,
{
let s = self
.0
.format(&time::format_description::well_known::Rfc3339)
.unwrap();
serializer
.write(merde_core::Event::Str(merde_core::CowStr::Borrowed(&s)))
.write(crate::Event::Str(crate::CowStr::Borrowed(&s)))
.await
}
}
Expand Down
144 changes: 0 additions & 144 deletions merde_time/CHANGELOG.md

This file was deleted.

28 changes: 0 additions & 28 deletions merde_time/Cargo.toml

This file was deleted.

14 changes: 0 additions & 14 deletions merde_time/README.md

This file was deleted.

0 comments on commit 47a5752

Please sign in to comment.