Skip to content

Commit

Permalink
Merge pull request #657 from tisonkun/relax-feature-flag
Browse files Browse the repository at this point in the history
Relax feature flag for value's std_support
  • Loading branch information
KodrAus authored Jan 10, 2025
2 parents 67e025a + a61f95d commit 0ce1442
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -432,20 +432,29 @@ mod std_support {
}
}

impl<'v> Value<'v> {
/// Try to convert this value into a string.
pub fn to_cow_str(&self) -> Option<Cow<'v, str>> {
self.inner.to_str()
}
}

impl<'v> From<&'v String> for Value<'v> {
fn from(v: &'v String) -> Self {
Value::from(&**v)
}
}
}

#[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<std::borrow::Cow<'v, str>> {
self.inner.to_str()
}
}

#[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<std::borrow::Cow<'v, str>> {
self.inner.to_borrowed_str().map(std::borrow::Cow::Borrowed)
}
}

/// A visitor for a [`Value`].
///
/// Also see [`Value`'s documentation on seralization]. Value visitors are a simple alternative
Expand Down

0 comments on commit 0ce1442

Please sign in to comment.