Skip to content

Commit

Permalink
remove example as it is over complicated
Browse files Browse the repository at this point in the history
  • Loading branch information
devkelley committed Jan 4, 2024
1 parent 87d1117 commit 94ee888
Showing 1 changed file with 0 additions and 42 deletions.
42 changes: 0 additions & 42 deletions proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,6 @@ use proc_macro::TokenStream;
///
/// # Arguments
/// * `ts`: A token stream.
///
/// # Examples
///
/// Given a Struct:
///
/// ```rust
/// pub struct CmdOptions {
/// pub endpoint: String,
/// pub log_level: Option<String>,
/// }
/// ```
///
/// The `ConfigSource` derive macro will implement `config::Source`:
///
/// ```rust
/// impl config::Source for CmdOptions {
/// fn clone_into_box(&self) -> Box<dyn config::Source + Send + Sync> {
/// Box::new((*self).clone())
/// }
///
/// fn collect(&self) -> Result<config::Map<String, config::Value>, config::ConfigError> {
/// let mut entries: config::Map::<String, Option<config::Value>> = config::Map::from([
/// (
/// String::from("endpoint"),
/// (&self.endpoint).clone().map(|v| config::Value::from(v))
/// ),
/// (
/// String::from("log_level"),
/// Some(config::Value::from((&self.log_level).clone()))
/// ),
/// ]);
///
/// entries.retain(|_, v| v.is_some());
/// let entries_w_values = entries.clone();
/// let valid_entries: config::Map::<String, config::Value> = entries_w_values.iter().map(|(k, v)| (k.clone(), v.clone().unwrap())).collect();
///
/// Ok(valid_entries.clone())
/// }
/// }
/// ```
///
/// This allows for Structs to be used as a `Source` for configuration through the `config` crate.
#[proc_macro_derive(ConfigSource)]
pub fn config_source(ts: TokenStream) -> TokenStream {
config_source::config_source(ts)
Expand Down

0 comments on commit 94ee888

Please sign in to comment.