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
impl ConfigBuilder
Sourcepub fn new() -> Self
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.
Sourcepub fn merge(self, other: Config) -> Self
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.
Sourcepub fn database(self, config: DatabaseConfig) -> Self
pub fn database(self, config: DatabaseConfig) -> Self
Set database configuration
Sourcepub fn network(self, config: NetworkConfig) -> Self
pub fn network(self, config: NetworkConfig) -> Self
Set network configuration
Sourcepub fn providers(self, config: ProvidersConfig) -> Self
pub fn providers(self, config: ProvidersConfig) -> Self
Set providers configuration
Sourcepub fn features(self, config: FeaturesConfig) -> Self
pub fn features(self, config: FeaturesConfig) -> Self
Set features configuration
Sourcepub fn port(self, port: u16) -> Self
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);Sourcepub fn log_level(self, level: LogLevel) -> Self
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);Sourcepub fn use_testnet(self, use_testnet: bool) -> Self
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);Sourcepub fn redis_url(self, url: String) -> Self
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");Sourcepub fn neo4j_url(self, url: Option<String>) -> Self
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()));Sourcepub fn solana_rpc_url(self, url: String) -> Self
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");Sourcepub fn default_chain_id(self, id: u64) -> Self
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);Sourcepub fn anthropic_api_key(self, key: Option<String>) -> Self
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());Sourcepub fn openai_api_key(self, key: Option<String>) -> Self
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());Sourcepub fn development(self) -> Self
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);Sourcepub fn staging(self) -> Self
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);Sourcepub fn production(self) -> Self
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);Sourcepub fn testnet(self) -> Self
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); // GoerliSourcepub fn mainnet(self) -> Self
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 MainnetSourcepub fn enable_trading(self, enabled: bool) -> Self
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);Sourcepub fn enable_graph_memory(self, enabled: bool) -> Self
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);Sourcepub fn from_file<P: AsRef<Path>>(self, path: P) -> ConfigResult<Self>
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();Sourcepub fn from_env(self) -> ConfigResult<Self>
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();Sourcepub fn validate(&self) -> ConfigResult<()>
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();
}Sourcepub fn build(self) -> ConfigResult<Config>
pub fn build(self) -> ConfigResult<Config>
Build the configuration
This validates all configuration and returns an error if any validation fails.