Skip to main content

Source

Trait Source 

Source
pub trait Source: Send + Sync {
    // Required methods
    fn load<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<ConfigValue>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn name(&self) -> &str;
}
👎Deprecated since 0.4.0: Use the Loader trait instead. Source will be removed in a future version.
Expand description

A source of configuration data.

Deprecated: Use the Loader trait instead. Loader participates in automatic plugin discovery via the registry, while Source requires manual construction and wiring. Source will be removed in a future major version.

EnvSource and MemorySource are not affected — they remain as layering utilities used by ConfigBuilder.

§Examples

use prefer::source::Source;
use prefer::{ConfigValue, Result};
use async_trait::async_trait;

struct MyCustomSource {
    data: ConfigValue,
}

#[async_trait]
impl Source for MyCustomSource {
    async fn load(&self) -> Result<ConfigValue> {
        Ok(self.data.clone())
    }

    fn name(&self) -> &str {
        "custom"
    }
}

Required Methods§

Source

fn load<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<ConfigValue>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

👎Deprecated since 0.4.0: Use the Loader trait instead. Source will be removed in a future version.

Load configuration data from this source.

Source

fn name(&self) -> &str

👎Deprecated since 0.4.0: Use the Loader trait instead. Source will be removed in a future version.

Get a human-readable name for this source (used in error messages).

Implementors§