Skip to main content

FieldDescriptor

Struct FieldDescriptor 

Source
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

Source

pub fn path(&self) -> &'static str

Returns the dotted path, such as listen.address.

Source

pub fn section(&self) -> &'static str

Returns the table the field lives in: the part of the path before the first dot.

Source

pub fn key(&self) -> &'static str

Returns the key within its table: the part of the path after the first dot.

Source

pub fn value_type(&self) -> ValueType

Returns the field’s type.

Source

pub fn default_value(&self) -> Value

Returns the value the field takes when a document omits it.

Source

pub fn description(&self) -> &'static str

Returns the one-paragraph, plain-text description.

Source

pub fn apply_class(&self) -> ApplyClass

Returns when a change to this field takes effect.

Source

pub fn is_secret_ref(&self) -> bool

Returns true if the field holds a secret reference.

Source

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.

Source§

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

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

impl Serialize for FieldDescriptor

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Forget for FieldDescriptor

§

impl Freeze for FieldDescriptor
where &'static str: Freeze, &'static [&'static str]: Freeze,

§

impl Move for FieldDescriptor

§

impl RefUnwindSafe for FieldDescriptor

§

impl Send for FieldDescriptor
where &'static str: Send, &'static [&'static str]: Send,

§

impl Sync for FieldDescriptor

§

impl Unpin for FieldDescriptor
where &'static str: Unpin, &'static [&'static str]: Unpin,

§

impl UnsafeUnpin for FieldDescriptor
where &'static str: UnsafeUnpin, &'static [&'static str]: UnsafeUnpin,

§

impl UnwindSafe for FieldDescriptor
where &'static str: UnwindSafe, &'static [&'static str]: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.