Skip to content

Commit

Permalink
value-bag distinct
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Jan 10, 2025
1 parent 34eb68c commit 8b06d9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -432,20 +433,21 @@ 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<Cow<'v, str>> {
self.inner.to_str()
}
}

/// A visitor for a [`Value`].
///
/// Also see [`Value`'s documentation on seralization]. Value visitors are a simple alternative
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 8b06d9b

Please sign in to comment.