ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder { /* private fields */ }
Expand description

Builder for creating Config instances programmatically

This builder provides a fluent API for constructing configuration objects piece by piece. The builder validates the configuration when build() is called.

§Examples

use riglr_config::{ConfigBuilder, AppConfig, Environment, LogLevel};

let config = ConfigBuilder::default()
    .app(AppConfig {
        environment: Environment::Development,
        log_level: LogLevel::Debug,
        ..Default::default()
    })
    .build()
    .expect("Failed to build config");

Implementations§

Source§

impl ConfigBuilder

Source

pub fn new() -> Self

Create a new ConfigBuilder with default values

This is equivalent to ConfigBuilder::default() but provides a more explicit API for builder pattern initialization.

Source

pub fn merge(self, other: Config) -> Self

Merge another configuration into this builder

Non-default values from the other config will override current values. This allows for layered configuration where later sources take precedence.

Source

pub fn app(self, config: AppConfig) -> Self

Set application configuration

Source

pub fn database(self, config: DatabaseConfig) -> Self

Set database configuration

Source

pub fn network(self, config: NetworkConfig) -> Self

Set network configuration

Source

pub fn providers(self, config: ProvidersConfig) -> Self

Set providers configuration

Source

pub fn features(self, config: FeaturesConfig) -> Self

Set features configuration

Source

pub fn port(self, port: u16) -> Self

Set the server port

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .port(8080)
    .build()
    .unwrap();
assert_eq!(config.app.port, 8080);
Source

pub fn log_level(self, level: LogLevel) -> Self

Set the log level

§Example
use riglr_config::{ConfigBuilder, LogLevel};

let config = ConfigBuilder::new()
    .log_level(LogLevel::Warn)
    .build()
    .unwrap();
assert_eq!(config.app.log_level, LogLevel::Warn);
Source

pub fn use_testnet(self, use_testnet: bool) -> Self

Set whether to use testnet

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .use_testnet(true)
    .build()
    .unwrap();
assert!(config.app.use_testnet);
Source

pub fn redis_url(self, url: String) -> Self

Set the Redis URL

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .redis_url("redis://localhost:6379".to_string())
    .build()
    .unwrap();
assert_eq!(config.database.redis_url, "redis://localhost:6379");
Source

pub fn neo4j_url(self, url: Option<String>) -> Self

Set the Neo4j URL (optional)

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .neo4j_url(Some("bolt://localhost:7687".to_string()))
    .build()
    .unwrap();
assert_eq!(config.database.neo4j_url, Some("bolt://localhost:7687".to_string()));
Source

pub fn solana_rpc_url(self, url: String) -> Self

Set the Solana RPC URL

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .solana_rpc_url("https://api.mainnet-beta.solana.com".to_string())
    .build()
    .unwrap();
assert_eq!(config.network.solana_rpc_url, "https://api.mainnet-beta.solana.com");
Source

pub fn default_chain_id(self, id: u64) -> Self

Set the default chain ID

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .default_chain_id(137) // Polygon mainnet
    .build()
    .unwrap();
assert_eq!(config.network.default_chain_id, 137);
Source

pub fn anthropic_api_key(self, key: Option<String>) -> Self

Set the Anthropic API key

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .anthropic_api_key(Some("sk-ant-...".to_string()))
    .build()
    .unwrap();
assert!(config.providers.anthropic_api_key.is_some());
Source

pub fn openai_api_key(self, key: Option<String>) -> Self

Set the OpenAI API key

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .openai_api_key(Some("sk-...".to_string()))
    .build()
    .unwrap();
assert!(config.providers.openai_api_key.is_some());
Source

pub fn development(self) -> Self

Configure for development environment

Sets up common development defaults:

  • Environment::Development
  • LogLevel::Debug
  • use_testnet = true
§Example
use riglr_config::{ConfigBuilder, Environment, LogLevel};

let config = ConfigBuilder::new()
    .development()
    .build()
    .unwrap();
assert_eq!(config.app.environment, Environment::Development);
assert_eq!(config.app.log_level, LogLevel::Debug);
assert!(config.app.use_testnet);
Source

pub fn staging(self) -> Self

Configure for staging environment

Sets up common staging defaults:

  • Environment::Staging
  • LogLevel::Info
  • use_testnet = true
§Example
use riglr_config::{ConfigBuilder, Environment, LogLevel};

let config = ConfigBuilder::new()
    .staging()
    .build()
    .unwrap();
assert_eq!(config.app.environment, Environment::Staging);
assert_eq!(config.app.log_level, LogLevel::Info);
assert!(config.app.use_testnet);
Source

pub fn production(self) -> Self

Configure for production environment

Sets up common production defaults:

  • Environment::Production
  • LogLevel::Info
  • use_testnet = false
§Example
use riglr_config::{ConfigBuilder, Environment, LogLevel};

let config = ConfigBuilder::new()
    .production()
    .redis_url("redis://redis.example.com:6379".to_string())
    .build()
    .unwrap();
assert_eq!(config.app.environment, Environment::Production);
assert_eq!(config.app.log_level, LogLevel::Info);
assert!(!config.app.use_testnet);
Source

pub fn testnet(self) -> Self

Configure for testnet usage

Sets up testnet-specific defaults:

  • use_testnet = true
  • solana_rpc_url = devnet RPC
  • default_chain_id = 5 (Goerli)
§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .testnet()
    .build()
    .unwrap();
assert!(config.app.use_testnet);
assert_eq!(config.network.default_chain_id, 5); // Goerli
Source

pub fn mainnet(self) -> Self

Configure for mainnet usage

Sets up mainnet-specific defaults:

  • use_testnet = false
  • solana_rpc_url = mainnet-beta RPC
  • default_chain_id = 1 (Ethereum Mainnet)
§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .mainnet()
    .build()
    .unwrap();
assert!(!config.app.use_testnet);
assert_eq!(config.network.default_chain_id, 1); // Ethereum Mainnet
Source

pub fn enable_trading(self, enabled: bool) -> Self

Set whether trading is enabled

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .enable_trading(false)
    .build()
    .unwrap();
assert!(!config.features.enable_trading);
Source

pub fn enable_graph_memory(self, enabled: bool) -> Self

Set whether graph memory is enabled

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .neo4j_url(Some("bolt://localhost:7687".to_string())) // Required for graph memory
    .enable_graph_memory(true)
    .build()
    .unwrap();
assert!(config.features.enable_graph_memory);
Source

pub fn from_file<P: AsRef<Path>>(self, path: P) -> ConfigResult<Self>

Load configuration from a TOML file

This method loads configuration from a TOML file and merges it with any existing builder settings.

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .from_file("config.toml")
    .unwrap()
    .port(8080) // Can override file settings
    .build()
    .unwrap();
Source

pub fn from_env(self) -> ConfigResult<Self>

Load configuration from environment variables

This method loads configuration from environment variables and merges it with any existing builder settings.

§Example
use riglr_config::ConfigBuilder;

let config = ConfigBuilder::new()
    .development()
    .from_env()
    .unwrap()
    .build()
    .unwrap();
Source

pub fn validate(&self) -> ConfigResult<()>

Validate the current configuration without building

This allows you to check if the configuration is valid before calling build().

§Example
use riglr_config::ConfigBuilder;

let builder = ConfigBuilder::new()
    .development();

// Check if valid before building
if builder.validate().is_ok() {
    let config = builder.build().unwrap();
}
Source

pub fn build(self) -> ConfigResult<Config>

Build the configuration

This validates all configuration and returns an error if any validation fails.

Trait Implementations§

Source§

impl Default for ConfigBuilder

Source§

fn default() -> ConfigBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,