macro_rules! macro_metadata_option {
($metadata:ident, $key:expr) => { ... };
}Expand description
§macro_metadata_option Macro
Extracts an option value from metadata.
§Usage
use std::collections::HashMap;
use rss_gen::macro_metadata_option;
let mut metadata = HashMap::new();
metadata.insert("key", "value");
let value = macro_metadata_option!(metadata, "key");
println!("{}", value);§Arguments
$metadata- A mutable variable that represents the metadata (of typeHashMap<String, String>or any other type that supports thegetandclonedmethods).$key- A string literal that represents the key to search for in the metadata.
§Behaviour
The macro_metadata_option macro is used to extract an option value from metadata. It takes a mutable variable representing the metadata and a string literal representing the key as arguments, and uses the get method of the metadata to find an option value with the specified key.
If the key exists in the metadata, the macro clones the value and returns it. If the key does not exist, it returns the default value for the type of the metadata values.
The macro is typically used in contexts where metadata is stored in a data structure that supports the get and cloned methods, such as a HashMap<String, String>.
§Example
use std::collections::HashMap;
use rss_gen::macro_metadata_option;
let mut metadata = HashMap::new();
metadata.insert("key".to_string(), "value".to_string());
let value = macro_metadata_option!(metadata, "key");
assert_eq!(value, "value");