From a41abf4e6549d39e37217416b51e2995d3f28c7e Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Fri, 13 Sep 2024 16:20:34 +0200 Subject: [PATCH] Make compact_str dependency optional, too --- Justfile | 4 ++-- merde-core/Cargo.toml | 7 ++++++- merde-core/src/cowstr.rs | 13 ++++++++++--- merde-core/src/deserialize.rs | 1 + zerodeps-example/Cargo.lock | 1 + zerodeps-example/Cargo.toml | 3 ++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Justfile b/Justfile index f13899f..7b84e73 100644 --- a/Justfile +++ b/Justfile @@ -8,6 +8,6 @@ check: pushd zerodeps-example cargo check cargo check --features=merde - cargo tree --prefix none --no-dedupe | grep -v compact_str - cargo tree --prefix none --no-dedupe --features=merde | grep compact_str + cargo tree --prefix none --no-dedupe | grep -v merde-core + cargo tree --prefix none --no-dedupe --features=merde | grep merde-core popd diff --git a/merde-core/Cargo.toml b/merde-core/Cargo.toml index 508918a..79a13db 100644 --- a/merde-core/Cargo.toml +++ b/merde-core/Cargo.toml @@ -11,4 +11,9 @@ keywords = ["merde", "serialization", "deserialization"] categories = ["encoding", "parser-implementations"] [dependencies] -compact_str = "0.8.0" +compact_str = { version = "0.8.0", optional = true } + +[features] +default = [] +full = ["compact_str"] +compact_str = ["dep:compact_str"] diff --git a/merde-core/src/cowstr.rs b/merde-core/src/cowstr.rs index 2987d90..94a211d 100644 --- a/merde-core/src/cowstr.rs +++ b/merde-core/src/cowstr.rs @@ -5,6 +5,7 @@ use std::{ ops::Deref, }; +#[cfg(feature = "compact_str")] use compact_str::CompactString; use crate::IntoStatic; @@ -17,7 +18,10 @@ use crate::IntoStatic; #[derive(Clone)] pub enum CowStr<'s> { Borrowed(&'s str), + #[cfg(feature = "compact_str")] Owned(CompactString), + #[cfg(not(feature = "compact_str"))] + Owned(String), } impl Deref for CowStr<'_> { @@ -35,7 +39,8 @@ impl<'a> From> for CowStr<'a> { fn from(s: Cow<'a, str>) -> Self { match s { Cow::Borrowed(s) => CowStr::Borrowed(s), - Cow::Owned(s) => CowStr::Owned(CompactString::from(s)), + #[allow(clippy::useless_conversion)] + Cow::Owned(s) => CowStr::Owned(s.into()), } } } @@ -48,13 +53,14 @@ impl<'s> From<&'s str> for CowStr<'s> { impl From for CowStr<'_> { fn from(s: String) -> Self { - CowStr::Owned(CompactString::from(s)) + #[allow(clippy::useless_conversion)] + CowStr::Owned(s.into()) } } impl From> for CowStr<'_> { fn from(s: Box) -> Self { - CowStr::Owned(CompactString::from(s)) + CowStr::Owned(s.into()) } } @@ -68,6 +74,7 @@ impl From> for String { fn from(s: CowStr<'_>) -> Self { match s { CowStr::Borrowed(s) => s.into(), + #[allow(clippy::useless_conversion)] CowStr::Owned(s) => s.into(), } } diff --git a/merde-core/src/deserialize.rs b/merde-core/src/deserialize.rs index 37cf740..ee8635d 100644 --- a/merde-core/src/deserialize.rs +++ b/merde-core/src/deserialize.rs @@ -55,6 +55,7 @@ impl<'s> ValueDeserialize<'s> for Cow<'s, str> { match value { Some(Value::Str(s)) => match s { CowStr::Borrowed(b) => Ok(Cow::Borrowed(b)), + #[allow(clippy::useless_conversion)] CowStr::Owned(o) => Ok(Cow::Owned(o.into())), }, Some(v) => Err(MerdeError::MismatchedType { diff --git a/zerodeps-example/Cargo.lock b/zerodeps-example/Cargo.lock index 4d442cd..0daa1ea 100644 --- a/zerodeps-example/Cargo.lock +++ b/zerodeps-example/Cargo.lock @@ -74,4 +74,5 @@ name = "zerodeps-example" version = "0.1.0" dependencies = [ "merde", + "merde-core", ] diff --git a/zerodeps-example/Cargo.toml b/zerodeps-example/Cargo.toml index 1ad9f15..6f1218a 100644 --- a/zerodeps-example/Cargo.toml +++ b/zerodeps-example/Cargo.toml @@ -6,7 +6,8 @@ publish = false [dependencies] merde = { version = "4.0.0", path = "../merde", default-features = false } +merde-core = { version = "4.0.0", path = "../merde-core", default-features = false } [features] default = [] -merde = ["merde/core"] +merde = ["merde/core", "merde-core/compact_str"]