Skip to content

Commit

Permalink
restore removed APIs as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Feb 18, 2024
1 parent 52460f9 commit 90a347b
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ kv_sval = ["kv", "value-bag/sval", "sval", "sval_ref"]
kv_std = ["std", "kv", "value-bag/error"]
kv_serde = ["kv_std", "value-bag/serde", "serde"]

# Legacy: use `kv_*` instead
# Deprecated: use `kv_*` instead
# These `*_unstable` features will be removed in a future release
kv_unstable = ["kv"]
kv_unstable_sval = ["kv_sval"]
kv_unstable_std = ["kv_std"]
Expand Down
11 changes: 11 additions & 0 deletions src/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,21 @@

mod error;
mod key;

#[cfg(not(feature = "kv_unstable"))]
mod source;
#[cfg(not(feature = "kv_unstable"))]
mod value;

pub use self::error::Error;
pub use self::key::{Key, ToKey};
pub use self::source::{Source, VisitSource};
pub use self::value::{ToValue, Value, VisitValue};

#[cfg(feature = "kv_unstable")]
pub mod source;
#[cfg(feature = "kv_unstable")]
pub mod value;

#[cfg(feature = "kv_unstable")]
pub use self::source::Visitor;
4 changes: 4 additions & 0 deletions src/kv/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ mod std_support {
}
}

// NOTE: Deprecated; but aliases can't carry this attribute
#[cfg(feature = "kv_unstable")]
pub use VisitSource as Visitor;

#[cfg(test)]
mod tests {
use crate::kv::value;
Expand Down
136 changes: 136 additions & 0 deletions src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ macro_rules! impl_to_value_primitive {
Value::from_inner(value)
}
}

impl<'v> From<&'v $into_ty> for Value<'v> {
fn from(value: &'v $into_ty) -> Self {
Value::from_inner(*value)
}
}
)*
};
}
Expand All @@ -316,6 +322,12 @@ macro_rules! impl_to_value_nonzero_primitive {
Value::from(value.get())
}
}

impl<'v> From<&'v std::num::$into_ty> for Value<'v> {
fn from(value: &'v std::num::$into_ty) -> Self {
Value::from(value.get())
}
}
)*
};
}
Expand Down Expand Up @@ -1034,6 +1046,130 @@ pub(in crate::kv) mod inner {
}
}

impl<'v> Value<'v> {
/// Get a value from a type implementing `std::fmt::Debug`.
#[cfg(feature = "kv_unstable")]
#[deprecated(note = "use `from_debug` instead")]
pub fn capture_debug<T>(value: &'v T) -> Self
where
T: fmt::Debug + 'static,
{
Value::from_debug(value)
}

/// Get a value from a type implementing `std::fmt::Display`.
#[cfg(feature = "kv_unstable")]
#[deprecated(note = "use `from_display` instead")]
pub fn capture_display<T>(value: &'v T) -> Self
where
T: fmt::Display + 'static,
{
Value::from_display(value)
}

/// Get a value from an error.
#[cfg(feature = "kv_unstable_std")]
#[deprecated(note = "use `from_dyn_error` instead")]
pub fn capture_error<T>(err: &'v T) -> Self
where
T: std::error::Error + 'static,
{
Value::from_dyn_error(err)
}

/// Get a value from a type implementing `serde::Serialize`.
#[cfg(feature = "kv_unstable_serde")]
#[deprecated(note = "use `from_serde` instead")]
pub fn capture_serde<T>(value: &'v T) -> Self
where
T: serde::Serialize + 'static,
{
Value::from_serde(value)
}

/// Get a value from a type implementing `sval::Value`.
#[cfg(feature = "kv_unstable_sval")]
#[deprecated(note = "use `from_sval` instead")]
pub fn capture_sval<T>(value: &'v T) -> Self
where
T: sval::Value + 'static,
{
Value::from_sval(value)
}

/// Check whether this value can be downcast to `T`.
#[cfg(feature = "kv_unstable")]
#[deprecated(
note = "downcasting has been removed; log an issue at https://github.com/rust-lang/log/issues if this is something you rely on"
)]
pub fn is<T: 'static>(&self) -> bool {
false
}

/// Try downcast this value to `T`.
#[cfg(feature = "kv_unstable")]
#[deprecated(
note = "downcasting has been removed; log an issue at https://github.com/rust-lang/log/issues if this is something you rely on"
)]
pub fn downcast_ref<T: 'static>(&self) -> Option<&T> {
None
}
}

// NOTE: Deprecated; but aliases can't carry this attribute
#[cfg(feature = "kv_unstable")]
pub use VisitValue as Visitor;

/// Get a value from a type implementing `std::fmt::Debug`.
#[cfg(feature = "kv_unstable")]
#[deprecated(note = "use the `key:? = value` macro syntax instead")]
#[macro_export]
macro_rules! as_debug {
($capture:expr) => {
$crate::kv::Value::from_debug(&$capture)
};
}

/// Get a value from a type implementing `std::fmt::Display`.
#[cfg(feature = "kv_unstable")]
#[deprecated(note = "use the `key:% = value` macro syntax instead")]
#[macro_export]
macro_rules! as_display {
($capture:expr) => {
$crate::kv::Value::from_display(&$capture)
};
}

/// Get a value from an error.
#[cfg(feature = "kv_unstable_std")]
#[deprecated(note = "use the `key:error = value` macro syntax instead")]
#[macro_export]
macro_rules! as_error {
($capture:expr) => {
$crate::kv::Value::from_dyn_error(&$capture)
};
}

#[cfg(feature = "kv_unstable_serde")]
#[deprecated(note = "use the `key:serde = value` macro syntax instead")]
/// Get a value from a type implementing `serde::Serialize`.
#[macro_export]
macro_rules! as_serde {
($capture:expr) => {
$crate::kv::Value::from_serde(&$capture)
};
}

/// Get a value from a type implementing `sval::Value`.
#[cfg(feature = "kv_unstable_sval")]
#[deprecated(note = "use the `key:sval = value` macro syntax instead")]
#[macro_export]
macro_rules! as_sval {
($capture:expr) => {
$crate::kv::Value::from_sval(&$capture)
};
}

#[cfg(test)]
pub(crate) mod tests {
use super::*;
Expand Down

0 comments on commit 90a347b

Please sign in to comment.