EnterpriseConfig

Struct EnterpriseConfig 

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

Enterprise-grade configuration manager with multi-tier caching and access control

EnterpriseConfig provides a high-performance configuration management system designed for production applications with strict performance requirements.

§Key Features

  • Multi-Tier Caching: Fast cache for hot values + main cache for all values
  • Lock-Free Performance: Optimized access patterns to minimize lock contention
  • Thread Safety: All operations are safe for concurrent access via Arc<RwLock>
  • Poison Recovery: Graceful handling of lock poisoning without panics
  • Format Preservation: Maintains original file format during save operations
  • Sub-50ns Access: Achieves sub-50 nanosecond access times for cached values

§Performance Characteristics

  • First access: ~3µs (populates cache)
  • Cached access: ~457ns average (hot cache hit)
  • Concurrent access: Maintains performance under load
  • Memory efficient: LRU-style cache with configurable limits

§Examples

use config_lib::enterprise::EnterpriseConfig;
use config_lib::Value;

// Load configuration with automatic caching
let mut config = EnterpriseConfig::from_string(r#"
    server.port = 8080
    server.host = "localhost"
    app.name = "my-service"
"#, Some("conf"))?;

// First access populates cache
let port = config.get("server.port");

// Subsequent accesses hit fast cache
let port_again = config.get("server.port"); // ~400ns

// Check cache performance
let (hits, misses, ratio) = config.cache_stats();
println!("Cache hit ratio: {:.1}%", ratio * 100.0);

Implementations§

Source§

impl EnterpriseConfig

Source

pub fn new() -> Self

Create new config with defaults

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>

Load configuration from file with caching

Source

pub fn from_string(content: &str, format: Option<&str>) -> Result<Self>

Load configuration from string with caching

Source

pub fn get(&self, key: &str) -> Option<Value>

Get value with default fallback - enterprise API with true caching

Source

pub fn get_or<T>(&self, key: &str, default: T) -> T
where T: From<Value> + Clone,

Get a value or return a default (ZERO-COPY optimized)

Source

pub fn get_or_default(&self, key: &str) -> Option<Value>

Get with default value from defaults table

Source

pub fn exists(&self, key: &str) -> bool

Check if key exists (enterprise API)

Source

pub fn set(&mut self, key: &str, value: Value) -> Result<()>

Set value in cache and invalidate fast cache

Source

pub fn cache_stats(&self) -> (u64, u64, f64)

Get cache performance statistics

Source

pub fn set_default(&mut self, key: &str, value: Value)

Set default value for key

Source

pub fn save(&self) -> Result<()>

Save configuration to file (format-preserving when possible)

Source

pub fn save_to<P: AsRef<Path>>(&self, path: P) -> Result<()>

Save to specific file

Source

pub fn keys(&self) -> Vec<String>

Get all keys (for debugging/inspection)

Source

pub fn make_read_only(&mut self)

Make config read-only for security

Source

pub fn clear(&mut self) -> Result<()>

Clear cache (enterprise operation)

Source

pub fn merge(&mut self, other: &EnterpriseConfig) -> Result<()>

Merge another config into this one

Trait Implementations§

Source§

impl Debug for EnterpriseConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EnterpriseConfig

Source§

fn default() -> Self

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, 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.