Skip to main content

ModuleInfoField

Enum ModuleInfoField 

Source
#[non_exhaustive]
pub enum ModuleInfoField { Binary, Version, ModuleVersion, Maintainer, Name, Type, Repo, Branch, Hash, Copyright, Os, OsVersion, }
Expand description

Represents the available module info fields

This enum provides a type-safe way to specify which module info field to access when using the get_module_info! macro.

§Non-exhaustive

This enum is marked #[non_exhaustive]: additional fields may be added in future minor releases without breaking SemVer. Any external match on ModuleInfoField must include a wildcard arm (_ => ...) so downstream code keeps compiling when new variants are introduced.

§Example

ModuleInfoField does not need to be imported when it only appears inside get_module_info!(ModuleInfoField::…): the macro pattern-matches the variant as tokens, so the bare macro + result import is enough:

use module_info::{get_module_info, ModuleInfoResult};

fn get_binary_name() -> ModuleInfoResult<String> {
    let binary_name = get_module_info!(ModuleInfoField::Binary)?;
    Ok(binary_name)
}

You only need use module_info::ModuleInfoField; when you reference the enum outside the macro (e.g. in your own match or when passing a value into ModuleInfoField::to_symbol_name).

§Adding a new variant

Adding a variant requires synchronized updates in seven places across four files. The enum #[non_exhaustive] + exhaustive matches in field_value/to_symbol_name/to_key catch most drift as compile errors, but the get_module_info! macro rules are token-matched and their drift only surfaces at the consumer’s call site. Skim this list:

  1. This enum declaration (add the variant)
  2. ModuleInfoField::to_symbol_name match arm (compile-error on miss)
  3. ModuleInfoField::to_key match arm (compile-error on miss)
  4. ModuleInfoField::ALL + EXPECTED_VARIANT_COUNT in the drift-guard test (runtime failure on miss)
  5. PackageMetadata field + field_value match arm (compile-error on miss)
  6. src/macros.rs: per-variant rule in the Linux get_module_info! macro AND in the non-Linux fallback macro. Missing a rule here is silent: get_module_info!(ModuleInfoField::NewField) only fails at the consumer’s call site.
  7. src/macros.rs: an @__add_to_map line in the no-arg form of the Linux get_module_info! macro. Missing this line silently drops the field from the no-arg HashMap.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Binary

The binary name

§

Version

The version of the binary

§

ModuleVersion

The version of the module

§

Maintainer

The maintainer of the binary

§

Name

The name of the module

§

Type

The type of module

§

Repo

The repository URL

§

Branch

The branch name

§

Hash

The commit hash

§

Copyright

The copyright information

§

Os

The operating system information

§

OsVersion

The operating system version

Implementations§

Source§

impl ModuleInfoField

Source

pub const ALL: &'static [ModuleInfoField]

All variants of ModuleInfoField, in a stable declaration order.

This single source-of-truth list is used by ModuleInfoField::count and by the no-argument form of the get_module_info! macro to build the result HashMap. Adding a variant above and forgetting to add it here will be caught by the agreement test in lib.rs.

Source

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

Converts the enum variant to the corresponding linker symbol name (for example, ModuleInfoField::Binary"module_info_binary").

This is primarily an internal helper used by the get_module_info! macro expansion and by debugging utilities; most consumers should reach for the macro rather than calling this directly.

§Returns

A string slice containing the symbol name for this field.

Source

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

Converts the enum variant to the JSON/HashMap key used for this field (for example, ModuleInfoField::ModuleVersion"moduleVersion").

This is primarily an internal helper used by the no-argument form of get_module_info!() when it assembles the result HashMap. Direct consumer use is uncommon; reach for the macro instead.

§Returns

A string slice containing the key for this field in the HashMap.

Source

pub const fn count() -> usize

Returns the number of variants in the ModuleInfoField enum.

Derived from ModuleInfoField::ALL so it stays in sync automatically when variants are added or removed.

Trait Implementations§

Source§

impl Clone for ModuleInfoField

Source§

fn clone(&self) -> ModuleInfoField

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModuleInfoField

Source§

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

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

impl PartialEq for ModuleInfoField

Source§

fn eq(&self, other: &ModuleInfoField) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ModuleInfoField

Source§

impl Eq for ModuleInfoField

Source§

impl StructuralPartialEq for ModuleInfoField

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.