Skip to content
Merged
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
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