DocumentedFieldsOpt

Trait DocumentedFieldsOpt 

Source
pub trait DocumentedFieldsOpt {
    const FIELD_DOCS: &'static [Option<&'static str>];
    const FIELD_NAMES: &'static [&'static str];

    // Provided method
    fn get_field_docs<T: AsRef<str>>(
        field_name: T,
    ) -> Result<&'static str, Error> { ... }
}
Expand description

The optional variant of DocumentedFields.

Required Associated Constants§

Source

const FIELD_DOCS: &'static [Option<&'static str>]

The static doc comments on each field or variant of this type, indexed by field/variant order.

Source

const FIELD_NAMES: &'static [&'static str]

Field names, as accepted by Self::get_field_docs.

Note that anonymous fields (i.e. fields in tuple structs), unless they have a custom name set, will be omitted from FIELD_NAMES. This means that in such cases, the indices of FIELD_NAMES will be misaligned with that of FIELD_DOCS.

It is therefore recommended to use Self::get_field_docs rather than the index to lookup the corresponding documentation.

Provided Methods§

Source

fn get_field_docs<T: AsRef<str>>(field_name: T) -> Result<&'static str, Error>

Get a field’s documentation using its name.

Note that for structs with anonymous fields (i.e. tuple structs), this method will always return Error::NoSuchField by default. For this case, you can either:

  1. use FIELD_DOCS directly instead;
  2. set a custom name for the anonymous field.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§