Struct ConfigLoader

Source
pub struct ConfigLoader<E> { /* private fields */ }
Expand description

An instance which holds the loader instance.

Implementations§

Source§

impl ConfigLoader<()>

A default realization.

Source

pub fn new<E>(source: Box<dyn ConfigLoaderSource>, stor: E) -> ConfigLoader<E>

Creates new instance.

§Arguments
  • source - a dynamic ConfigLoaderSource instance which performs loading.

  • stor - a generic which can be used as a special storage.

§Returns

An instance of the ConfigLoader is returned.

Source§

impl<E> ConfigLoader<E>

Source

pub fn load_file<D, P>( &self, env_ser: &str, filepath: P, ) -> Result<ConfigLoaded<D>, String>
where D: DeserializeOwned + Clone, P: AsRef<Path>,

Loads a file by the provided path and parses it.

§Arguments
  • env_ser - A serializator name of the scheme serializator. If loaded from non local loaders this value may be ignored by the inner loader.

  • filepath - A path to the file. Depending on the inner loader realization, the path is partial i.e from the basepath of your config files. For example: the config files are physically located at /etc/myprogram, so the path to the server.shm will be /server.shm.

A Result is returned with the:

  • [Result::Ok()] is returned with inner type ConfigLoaded which contains a deserialized structure or enumerator, source and path.

  • [Result::Err()] is returned with the error description.

Source

pub fn read_raw_file<P>(&self, filepath: P) -> Result<String, String>
where P: AsRef<Path>,

Just reads the file and returns its content back as UTF-8 [Stirng]. This can be used for non config files. However for small one. For a large which content is large and will less likly fit in the RAM, use read_raw_file_buffered.

Source

pub fn get_storage(&self) -> &E

Source

pub fn get_storage_mut(&mut self) -> &mut E

Source

pub fn is_local(&self) -> bool

Source

pub fn get_serializator<S>( &self, serial_name: S, ) -> Result<Arc<DynEnvironment>, String>
where S: AsRef<str>,

Source

pub fn make_config<R, F>(self) -> Result<R, F>
where R: TryFrom<E, Error = F>,

Auto Trait Implementations§

§

impl<E> Freeze for ConfigLoader<E>
where E: Freeze,

§

impl<E> !RefUnwindSafe for ConfigLoader<E>

§

impl<E> !Send for ConfigLoader<E>

§

impl<E> !Sync for ConfigLoader<E>

§

impl<E> Unpin for ConfigLoader<E>
where E: Unpin,

§

impl<E> !UnwindSafe for ConfigLoader<E>

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.