From 90a347bd836873264a393a35bfd90fe478fadae2 Mon Sep 17 00:00:00 2001 From: KodrAus Date: Mon, 19 Feb 2024 07:22:40 +1000 Subject: [PATCH] restore removed APIs as deprecated --- Cargo.toml | 3 +- src/kv/mod.rs | 11 ++++ src/kv/source.rs | 4 ++ src/kv/value.rs | 136 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5992d0a9e..3074e9cfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/kv/mod.rs b/src/kv/mod.rs index 44f7b06df..6dbfe6f66 100644 --- a/src/kv/mod.rs +++ b/src/kv/mod.rs @@ -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; diff --git a/src/kv/source.rs b/src/kv/source.rs index 33d5a1a73..0ca267ce3 100644 --- a/src/kv/source.rs +++ b/src/kv/source.rs @@ -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; diff --git a/src/kv/value.rs b/src/kv/value.rs index 6bfff4e4e..96cb411d1 100644 --- a/src/kv/value.rs +++ b/src/kv/value.rs @@ -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) + } + } )* }; } @@ -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()) + } + } )* }; } @@ -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(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(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(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(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(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(&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(&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::*;