pub struct FieldDescriptor { /* private fields */ }Expand description
One field of the schema: its path, type, default, description and apply class.
Descriptors are obtained from Schema::fields or Schema::field; they
cannot be constructed outside this crate.
§Examples
use stratum_node_config::{schema, ApplyClass, Value};
let field = schema().field("limits.max_body_bytes").ok_or("missing field")?;
assert_eq!(field.apply_class(), ApplyClass::Restart);
assert_eq!(field.default_value(), Value::Integer(262_144));
assert!(field.validate(&Value::Integer(10)).is_err());Implementations§
Source§impl FieldDescriptor
impl FieldDescriptor
Sourcepub fn section(&self) -> &'static str
pub fn section(&self) -> &'static str
Returns the table the field lives in: the part of the path before the first dot.
Sourcepub fn key(&self) -> &'static str
pub fn key(&self) -> &'static str
Returns the key within its table: the part of the path after the first dot.
Sourcepub fn value_type(&self) -> ValueType
pub fn value_type(&self) -> ValueType
Returns the field’s type.
Sourcepub fn default_value(&self) -> Value
pub fn default_value(&self) -> Value
Returns the value the field takes when a document omits it.
Sourcepub fn description(&self) -> &'static str
pub fn description(&self) -> &'static str
Returns the one-paragraph, plain-text description.
Sourcepub fn apply_class(&self) -> ApplyClass
pub fn apply_class(&self) -> ApplyClass
Returns when a change to this field takes effect.
Sourcepub fn is_secret_ref(&self) -> bool
pub fn is_secret_ref(&self) -> bool
Returns true if the field holds a secret reference.
Sourcepub fn validate(&self, value: &Value) -> Result<(), ValidationError>
pub fn validate(&self, value: &Value) -> Result<(), ValidationError>
Checks value against this field’s type, range and rule.
Cross-field rules, such as the state and backup directories having to
differ, are only checked by ConfigDocument::parse.
§Errors
Returns a ValidationError at this field’s path when the value has
the wrong type, is out of range, or breaks the field’s rule.
Trait Implementations§
Source§impl Debug for FieldDescriptor
Shows the path, type, default and apply class; the description and rule
are elided.
impl Debug for FieldDescriptor
Shows the path, type, default and apply class; the description and rule are elided.