Skip to main content

OptionDeclMetadata

Struct OptionDeclMetadata 

Source
pub struct OptionDeclMetadata {
    pub name: &'static str,
    pub doc: &'static str,
    pub customizable: bool,
    pub group_name: &'static str,
    pub type_label: fn() -> &'static str,
    pub default_formatted: fn() -> String,
    pub type_id: fn() -> TypeId,
    pub register_fn: fn(&ConfigRegistry),
}
Expand description

Metadata captured at macro expansion for one option. The register function pointer is monomorphised at the call site so the registry boot path can register every option without pulling each <T> into a generic over the slice.

register_fn returns () and inserts the option into the crate::ConfigRegistry it is handed (via crate::ConfigRegistry::register_with_typeid); crate::ConfigRegistry::init_from_linkme calls it once per element of OPTION_DECLS.

Also the data the browse surfaces read without a registry: :customize groups by Self::group_name and hides entries whose Self::customizable is false.

Fields§

§name: &'static str

The option’s OptionDecl::NAME — its :set / TOML key.

§doc: &'static str

The option’s OptionDecl::DOC.

§customizable: bool

The option’s OptionDecl::CUSTOMIZABLE; false hides it from :customize.

§group_name: &'static str

The owning group’s display name (HasGroup::GROUP_NAME), which :customize <group> matches against.

§type_label: fn() -> &'static str

&'static str produced by the value type’s OptionType::type_label – captured as a function pointer so the slice element can be a static (the trait method isn’t const, so calling it directly in a static initializer fails). Resolved at the registry boot loop; cheap (one function call per option, once).

§default_formatted: fn() -> String

Format the type’s default value for diagnostic surfaces (:describe-option “default: X”). Captured as a function pointer so the slice element stays object-safe-shaped.

§type_id: fn() -> TypeId

TypeId::of::<Self>() for the declaration type. Same as <T as OptionDecl>::type_id() at the macro call site; pre-computed so the boot loop doesn’t pay the indirection.

§register_fn: fn(&ConfigRegistry)

Self-registration thunk. Called by the registry’s init_from_linkme boot loop with the registry as argument; the thunk constructs the runtime crate::option::Option<T> spec via Self::build_spec() and calls registry.register_with_typeid. The register_fn is generated by the crate::options! macro and captures the option’s type identity at compile time. Boot panics (with the option’s name in the message) if any registration fails – duplicate names at startup are a build-config bug.

Implementations§

Source§

impl OptionDeclMetadata

Source

pub const fn for_decl<D: OptionDecl + HasGroup>( type_label: fn() -> &'static str, default_formatted: fn() -> String, register_fn: fn(&ConfigRegistry), ) -> Self

Construct a metadata record for the given declaration type. Helper used by the crate::options! macro’s generated code; not intended for hand-call.

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more