Skip to main content

Config

Struct Config 

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

Thread-safe configuration store.

Provides flat key-value storage with type-safe accessors. Keys use dot notation for logical grouping: editor.theme, plugin.lsp.timeout

§Thread Safety

All operations are thread-safe via internal RwLock. Multiple readers allowed, single writer for mutations.

§Example

use reovim_kernel::api::v1::{Config, ConfigValue};

let config = Config::new();

// Set values
config.set_str("editor.theme", "dark");
config.set_int("editor.tabwidth", 4);

// Get values
assert_eq!(config.get_str("editor.theme"), Some("dark".to_string()));
assert_eq!(config.get_int("editor.tabwidth"), Some(4));

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

Create a new empty configuration.

Source

pub fn with_path(path: PathBuf) -> Self

Create a configuration with an associated file path.

Source

pub fn path(&self) -> Option<PathBuf>

Get the associated file path.

Source

pub fn set_path(&self, path: PathBuf)

Set the associated file path.

Source

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

Get a configuration value by key.

Keys use dot notation: editor.theme, plugin.lsp.timeout

Source

pub fn get_bool(&self, key: &str) -> Option<bool>

Get a boolean value.

Source

pub fn get_int(&self, key: &str) -> Option<i64>

Get an integer value.

Source

pub fn get_str(&self, key: &str) -> Option<String>

Get a string value.

Source

pub fn get_or(&self, key: &str, default: ConfigValue) -> ConfigValue

Get a value with a default fallback.

Source

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

Get a boolean with a default.

Source

pub fn get_int_or(&self, key: &str, default: i64) -> i64

Get an integer with a default.

Source

pub fn get_str_or(&self, key: &str, default: &str) -> String

Get a string with a default.

Source

pub fn set(&self, key: &str, value: ConfigValue)

Set a configuration value.

Keys use dot notation. Previous value is overwritten.

Source

pub fn set_bool(&self, key: &str, value: bool)

Set a boolean value.

Source

pub fn set_int(&self, key: &str, value: i64)

Set an integer value.

Source

pub fn set_str(&self, key: &str, value: impl Into<String>)

Set a string value.

Source

pub fn remove(&self, key: &str) -> Option<ConfigValue>

Remove a configuration key.

Returns the removed value if it existed.

Source

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

Check if a key exists.

Source

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

Get all keys.

Source

pub fn keys_with_prefix(&self, prefix: &str) -> Vec<String>

Get all keys matching a prefix.

Source

pub fn clear(&self)

Clear all configuration data.

Source

pub fn len(&self) -> usize

Get the number of entries.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn merge(&self, other: &Self)

Merge another config into this one.

Values from other overwrite values in self.

Source

pub fn to_map(&self) -> HashMap<String, ConfigValue>

Export all data as a HashMap.

Source

pub fn from_map(&self, map: HashMap<String, ConfigValue>)

Import data from a HashMap.

Trait Implementations§

Source§

impl Debug for Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Config

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.