Struct smart_config::ConfigSchema
source · pub struct ConfigSchema { /* private fields */ }
Expand description
Schema for configuration. Can contain multiple configs bound to different paths.
Implementations§
source§impl ConfigSchema
impl ConfigSchema
sourcepub fn new(metadata: &'static ConfigMetadata, prefix: &'static str) -> Self
pub fn new(metadata: &'static ConfigMetadata, prefix: &'static str) -> Self
Creates a schema consisting of a single configuration at the specified prefix.
sourcepub fn coerce_serde_enums(&mut self, coerce: bool) -> &mut Self
pub fn coerce_serde_enums(&mut self, coerce: bool) -> &mut Self
Switches coercing for serde-like enums. Coercion will add path aliases for all tagged params in enum configs
added to the schema afterward (or until coerce_serde_enums(false)
is called). Coercion will apply
to nested enum configs as well.
For example, if a config param named param
corresponds to the tag SomeTag
, then alias .some_tag.param
(snake_cased
tag + param name) will be added for the param. Tag aliases and param aliases will result
in additional path aliases, as expected. For example, if param
has alias alias
and the tag has alias AliasTag
,
then the param will have .alias_tag.param
, .alias_tag.alias
and .some_tag.alias
aliases.
sourcepub fn iter(&self) -> impl Iterator<Item = ConfigRef<'_>> + '_
pub fn iter(&self) -> impl Iterator<Item = ConfigRef<'_>> + '_
Iterates over all configs contained in this schema. A unique key for a config is its type + location; i.e., multiple returned refs may have the same config type xor same location (never both).
sourcepub fn locate(
&self,
metadata: &'static ConfigMetadata,
) -> impl Iterator<Item = &str> + '_
pub fn locate( &self, metadata: &'static ConfigMetadata, ) -> impl Iterator<Item = &str> + '_
Lists all prefixes for the specified config. This does not include aliases.
sourcepub fn get<'s>(
&'s self,
metadata: &'static ConfigMetadata,
prefix: &'s str,
) -> Option<ConfigRef<'s>>
pub fn get<'s>( &'s self, metadata: &'static ConfigMetadata, prefix: &'s str, ) -> Option<ConfigRef<'s>>
Gets a reference to a config by ist unique key (metadata + canonical prefix).
sourcepub fn get_mut(
&mut self,
metadata: &'static ConfigMetadata,
prefix: &str,
) -> Option<ConfigMut<'_>>
pub fn get_mut( &mut self, metadata: &'static ConfigMetadata, prefix: &str, ) -> Option<ConfigMut<'_>>
Gets a reference to a config by ist unique key (metadata + canonical prefix).
sourcepub fn single(&self, metadata: &'static ConfigMetadata) -> Result<ConfigRef<'_>>
pub fn single(&self, metadata: &'static ConfigMetadata) -> Result<ConfigRef<'_>>
Returns a single reference to the specified config.
§Errors
Returns an error if the configuration is not registered or has more than one mount point.
sourcepub fn single_mut(
&mut self,
metadata: &'static ConfigMetadata,
) -> Result<ConfigMut<'_>>
pub fn single_mut( &mut self, metadata: &'static ConfigMetadata, ) -> Result<ConfigMut<'_>>
Returns a single mutable reference to the specified config.
§Errors
Returns an error if the configuration is not registered or has more than one mount point.
sourcepub fn insert(
&mut self,
metadata: &'static ConfigMetadata,
prefix: &'static str,
) -> Result<ConfigMut<'_>>
pub fn insert( &mut self, metadata: &'static ConfigMetadata, prefix: &'static str, ) -> Result<ConfigMut<'_>>
Inserts a new configuration type at the specified place.
§Errors
Returns an error if adding a config leads to violations of fundamental invariants:
- If a parameter in the new config (taking aliases into account, and params in nested / flattened configs) is mounted at the location of an existing config.
- Vice versa, if a config or nested config is mounted at the location of an existing param.
- If a parameter is mounted at the location of a parameter with disjoint expected types.
Trait Implementations§
source§impl Clone for ConfigSchema
impl Clone for ConfigSchema
source§fn clone(&self) -> ConfigSchema
fn clone(&self) -> ConfigSchema
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ConfigSchema
impl Debug for ConfigSchema
source§impl Default for ConfigSchema
impl Default for ConfigSchema
source§fn default() -> ConfigSchema
fn default() -> ConfigSchema
Auto Trait Implementations§
impl Freeze for ConfigSchema
impl !RefUnwindSafe for ConfigSchema
impl Send for ConfigSchema
impl Sync for ConfigSchema
impl Unpin for ConfigSchema
impl !UnwindSafe for ConfigSchema
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)