From 34eb68cc577797ef82b8253d35a19770fc0857b4 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 10 Jan 2025 08:36:04 +0800 Subject: [PATCH 1/4] Relax feature flag for value's std_support Signed-off-by: tison --- src/kv/value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kv/value.rs b/src/kv/value.rs index 2b9ca2510..a4285fe38 100644 --- a/src/kv/value.rs +++ b/src/kv/value.rs @@ -385,7 +385,7 @@ impl<'v> Value<'v> { } } -#[cfg(feature = "kv_std")] +#[cfg(feature = "std")] mod std_support { use std::borrow::Cow; use std::rc::Rc; From 8b06d9bfe3a8031bfbaa7cfae22494cd94ab5ca7 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 10 Jan 2025 08:45:35 +0800 Subject: [PATCH 2/4] value-bag distinct Signed-off-by: tison --- src/kv/value.rs | 16 +++++++++------- src/lib.rs | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/kv/value.rs b/src/kv/value.rs index a4285fe38..d74dd0720 100644 --- a/src/kv/value.rs +++ b/src/kv/value.rs @@ -3,6 +3,7 @@ //! This module defines the [`Value`] type and supporting APIs for //! capturing and serializing them. +use alloc::borrow::Cow; use std::fmt; pub use crate::kv::Error; @@ -432,13 +433,6 @@ mod std_support { } } - impl<'v> Value<'v> { - /// Try to convert this value into a string. - pub fn to_cow_str(&self) -> Option> { - self.inner.to_str() - } - } - impl<'v> From<&'v String> for Value<'v> { fn from(v: &'v String) -> Self { Value::from(&**v) @@ -446,6 +440,14 @@ mod std_support { } } +#[cfg(all(feature = "std", feature = "value-bag"))] +impl<'v> Value<'v> { + /// Try to convert this value into a string. + pub fn to_cow_str(&self) -> Option> { + self.inner.to_str() + } +} + /// A visitor for a [`Value`]. /// /// Also see [`Value`'s documentation on seralization]. Value visitors are a simple alternative diff --git a/src/lib.rs b/src/lib.rs index 2e70f3141..f7b8011a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -389,6 +389,7 @@ compile_error!("multiple release_max_level_* features set"); #[cfg(all(not(feature = "std"), not(test)))] extern crate core as std; +extern crate alloc; use std::cfg; #[cfg(feature = "std")] From 2db4a1bb3011d93982667167b8f09c2a1288e7f4 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 10 Jan 2025 08:47:01 +0800 Subject: [PATCH 3/4] add test Signed-off-by: tison --- .github/workflows/main.yml | 1 + src/kv/value.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f1eab4b88..892a630be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,6 +47,7 @@ jobs: - run: cargo test --verbose --features kv - run: cargo test --verbose --features kv_sval - run: cargo test --verbose --features kv_serde + - run: cargo test --verbose --features kv,std - run: cargo test --verbose --features "kv kv_std kv_sval kv_serde" - run: cargo run --verbose --manifest-path test_max_level_features/Cargo.toml - run: cargo run --verbose --manifest-path test_max_level_features/Cargo.toml --release diff --git a/src/kv/value.rs b/src/kv/value.rs index d74dd0720..067469b75 100644 --- a/src/kv/value.rs +++ b/src/kv/value.rs @@ -448,6 +448,14 @@ impl<'v> Value<'v> { } } +#[cfg(all(feature = "std", not(feature = "value-bag")))] +impl<'v> Value<'v> { + /// Try to convert this value into a string. + pub fn to_cow_str(&self) -> Option> { + self.inner.to_borrowed_str().map(Cow::Borrowed) + } +} + /// A visitor for a [`Value`]. /// /// Also see [`Value`'s documentation on seralization]. Value visitors are a simple alternative From a61f95d19a1f841ca8fe82f0130f81f8d7aa74ee Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 10 Jan 2025 08:49:25 +0800 Subject: [PATCH 4/4] tidy Signed-off-by: tison --- src/kv/value.rs | 7 +++---- src/lib.rs | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/kv/value.rs b/src/kv/value.rs index 067469b75..6616ee961 100644 --- a/src/kv/value.rs +++ b/src/kv/value.rs @@ -3,7 +3,6 @@ //! This module defines the [`Value`] type and supporting APIs for //! capturing and serializing them. -use alloc::borrow::Cow; use std::fmt; pub use crate::kv::Error; @@ -443,7 +442,7 @@ mod std_support { #[cfg(all(feature = "std", feature = "value-bag"))] impl<'v> Value<'v> { /// Try to convert this value into a string. - pub fn to_cow_str(&self) -> Option> { + pub fn to_cow_str(&self) -> Option> { self.inner.to_str() } } @@ -451,8 +450,8 @@ impl<'v> Value<'v> { #[cfg(all(feature = "std", not(feature = "value-bag")))] impl<'v> Value<'v> { /// Try to convert this value into a string. - pub fn to_cow_str(&self) -> Option> { - self.inner.to_borrowed_str().map(Cow::Borrowed) + pub fn to_cow_str(&self) -> Option> { + self.inner.to_borrowed_str().map(std::borrow::Cow::Borrowed) } } diff --git a/src/lib.rs b/src/lib.rs index f7b8011a5..2e70f3141 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -389,7 +389,6 @@ compile_error!("multiple release_max_level_* features set"); #[cfg(all(not(feature = "std"), not(test)))] extern crate core as std; -extern crate alloc; use std::cfg; #[cfg(feature = "std")]