Skip to main content

Config

Struct Config 

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

Конфигурация GNUnet (GNUNET_CONFIGURATION_Handle).

Имена секций и опций не чувствительны к регистру. clone создаёт независимую копию.

let cfg = Config::load("peer.conf")?;
assert!(cfg.get_string("PATHS", "GNUNET_HOME").is_some());
let mut cfg = Config::new();
cfg.set_string("SECTION", "KEY", "value");
assert_eq!(cfg.get_string("SECTION", "KEY").as_deref(), Some("value"));

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

Пустая конфигурация без единой опции.

Source

pub fn load(path: impl AsRef<Path>) -> Result<Self, ConfigError>

Загружает значения по умолчанию из установки GNUnet и поверх них указанный файл (GNUNET_CONFIGURATION_load).

Source

pub fn load_default() -> Result<Self, ConfigError>

Загружает конфигурацию пользователя из места по умолчанию (обычно ~/.config/gnunet.conf), как это делают программы GNUnet без ключа -c.

Source

pub fn get_string(&self, section: &str, option: &str) -> Option<String>

Значение опции как текст, без раскрытия $-переменных. None, если опции нет.

Source

pub fn get_number(&self, section: &str, option: &str) -> Option<u64>

Значение опции как целое число. None, если опции нет или значение не является числом.

Source

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

Значение опции вида YES или NO. None, если опции нет или значение иное.

Source

pub fn get_time(&self, section: &str, option: &str) -> Option<Duration>

Срок из значения вида 5 min (GNUNET_CONFIGURATION_get_value_time); forever даёт Duration::MAX.

Source

pub fn get_size(&self, section: &str, option: &str) -> Option<u64>

Размер в байтах из значения вида 10 MiB (GNUNET_CONFIGURATION_get_value_size).

Source

pub fn get_float(&self, section: &str, option: &str) -> Option<f32>

Значение опции как дробное число.

Source

pub fn get_filename(&self, section: &str, option: &str) -> Option<PathBuf>

Имя файла с раскрытыми $-переменными (GNUNET_CONFIGURATION_get_value_filename).

Source

pub fn has_value(&self, section: &str, option: &str) -> bool

Задана ли опция.

Source

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

Имена всех секций (GNUNET_CONFIGURATION_iterate_sections).

Source

pub fn section_values(&self, section: &str) -> Vec<(String, String)>

Опции одной секции (GNUNET_CONFIGURATION_iterate_section_values).

Source

pub fn entries(&self) -> Vec<(String, String, String)>

Все тройки (секция, опция, значение) (GNUNET_CONFIGURATION_iterate).

Source

pub fn remove_section(&mut self, section: &str)

Удаляет секцию со всеми опциями.

Source

pub fn set_float(&mut self, section: &str, option: &str, value: f32)

Задаёт опцию дробным числом.

Source

pub fn serialize(&self) -> String

Текст конфигурации в формате файла (GNUNET_CONFIGURATION_serialize).

Source

pub fn merge_text(&mut self, text: &str) -> bool

Добавляет опции из текста в формате файла (GNUNET_CONFIGURATION_deserialize). false, если текст не разобран.

Source

pub fn expand_dollar(&self, text: &str) -> String

Раскрывает $VAR и ${VAR:-default} по секции PATHS и окружению (GNUNET_CONFIGURATION_expand_dollar).

Source

pub fn set_string(&mut self, section: &str, option: &str, value: &str)

Задаёт опцию текстом; прежнее значение заменяется.

Source

pub fn set_number(&mut self, section: &str, option: &str, value: u64)

Задаёт опцию целым числом.

Source

pub fn write(&self, path: impl AsRef<Path>) -> Result<(), ConfigError>

Записывает конфигурацию в файл в формате gnunet.conf.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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() -> Self

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

impl Drop for Config

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.