pub struct Config {
pub network: NetworkConfig,
pub security: SecurityConfig,
pub storage: StorageConfig,
pub dht: DhtConfig,
pub transport: TransportConfig,
pub identity: IdentityConfig,
}Expand description
Main configuration structure for the P2P network
Fields§
§network: NetworkConfigNetwork configuration
security: SecurityConfigSecurity configuration
storage: StorageConfigStorage configuration
dht: DhtConfigDHT configuration
transport: TransportConfigTransport configuration
identity: IdentityConfigIdentity configuration
Implementations§
Source§impl Config
impl Config
Sourcepub fn load() -> Result<Self>
pub fn load() -> Result<Self>
Load configuration from multiple sources with precedence:
- Environment variables (highest)
- Configuration file
- Default values (lowest)
§Examples
use saorsa_core::config::Config;
// Load with default locations
let config = Config::load()?;
// Access configuration values
println!("Listen address: {}", config.network.listen_address);
println!("Rate limit: {}", config.security.rate_limit);Sourcepub fn load_with_path<P: AsRef<Path>>(path: Option<P>) -> Result<Self>
pub fn load_with_path<P: AsRef<Path>>(path: Option<P>) -> Result<Self>
Load configuration with a specific config file path
§Examples
use saorsa_core::config::Config;
// Load from specific file
let config = Config::load_with_path(Some("custom.toml"))?;
// Load from optional path
let path = std::env::var("CONFIG_PATH").ok();
let config = Config::load_with_path(path.as_ref())?;Sourcepub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load configuration from a TOML file
Sourcepub fn save_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
Save configuration to a TOML file
Sourcepub fn development() -> Self
pub fn development() -> Self
Create development configuration
Sourcepub fn production() -> Self
pub fn production() -> Self
Create production configuration with secure defaults
Sourcepub fn listen_socket_addr(&self) -> Result<SocketAddr>
pub fn listen_socket_addr(&self) -> Result<SocketAddr>
Get parsed listen address
Sourcepub fn bootstrap_addrs(&self) -> Result<Vec<NetworkAddress>>
pub fn bootstrap_addrs(&self) -> Result<Vec<NetworkAddress>>
Get parsed bootstrap addresses
Sourcepub fn parse_size(size: &str) -> Result<u64>
pub fn parse_size(size: &str) -> Result<u64>
Sourcepub fn storage_max_size_bytes(&self) -> Result<u64>
pub fn storage_max_size_bytes(&self) -> Result<u64>
Get storage max size in bytes
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.