feat(kv): add kv wrapper for executing kv tasks (#2384)

This commit is contained in:
Kartikeya Hegde
2023-10-09 18:40:58 +05:30
committed by GitHub
parent e02838eb5d
commit 8b50997e56
18 changed files with 547 additions and 186 deletions

View File

@ -538,3 +538,41 @@ pub fn validate_config(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
.unwrap_or_else(|error| error.into_compile_error())
.into()
}
/// Generates the function to get the value out of enum variant
/// Usage
/// ```
/// #[derive(TryGetEnumVariant)]
/// #[error(RedisError(UnknownResult))]
/// struct Result {
/// Set(String),
/// Get(i32)
/// }
/// ```
///
/// This will generate the function to get `String` and `i32` out of the variants
///
/// ```
/// impl Result {
/// fn try_into_get(&self)-> Result<i32, RedisError> {
/// match self {
/// Self::Get(a) => Ok(a),
/// _=>Err(RedisError::UnknownResult)
/// }
/// }
///
/// fn try_into_set(&self)-> Result<String, RedisError> {
/// match self {
/// Self::Set(a) => Ok(a),
/// _=>Err(RedisError::UnknownResult)
/// }
/// }
/// }
#[proc_macro_derive(TryGetEnumVariant, attributes(error))]
pub fn try_get_enum_variant(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = syn::parse_macro_input!(input as syn::DeriveInput);
macros::try_get_enum::try_get_enum_variant(input)
.unwrap_or_else(|error| error.into_compile_error())
.into()
}