Skip to main content

forward_source

Macro forward_source 

Source
macro_rules! forward_source {
    ($inner:tt) => { ... };
    ($inner:tt; except $($skip:ident),* $(,)?) => { ... };
}
Expand description

Generate the forwarding body of every Source hook inside a wrapper’s impl Source for … block.

forward_source!(field) forwards every hook to self.field; forward_source!(field; except a, b) leaves out the hooks the wrapper defines itself (or deliberately leaves at the trait default). See the module docs for the rules.

use faucet_core::{FaucetError, Source, Value, async_trait, forward_source};
use std::collections::HashMap;

/// Stamps a fixed state key on any source; everything else reaches `inner`.
struct Keyed {
    inner: Box<dyn Source>,
    key: String,
}

#[async_trait]
impl Source for Keyed {
    fn state_key(&self) -> Option<String> {
        Some(self.key.clone())
    }
    forward_source!(inner; except state_key);
}