#[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:
- This enum declaration (add the variant)
ModuleInfoField::to_symbol_namematch arm (compile-error on miss)ModuleInfoField::to_keymatch arm (compile-error on miss)ModuleInfoField::ALL+EXPECTED_VARIANT_COUNTin the drift-guard test (runtime failure on miss)PackageMetadatafield +field_valuematch arm (compile-error on miss)src/macros.rs: per-variant rule in the Linuxget_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.src/macros.rs: an@__add_to_mapline in the no-arg form of the Linuxget_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
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
impl ModuleInfoField
Sourcepub const ALL: &'static [ModuleInfoField]
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.
Sourcepub fn to_symbol_name(&self) -> &'static str
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.
Sourcepub fn to_key(&self) -> &'static str
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.
Sourcepub const fn count() -> usize
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
impl Clone for ModuleInfoField
Source§fn clone(&self) -> ModuleInfoField
fn clone(&self) -> ModuleInfoField
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ModuleInfoField
impl Debug for ModuleInfoField
Source§impl PartialEq for ModuleInfoField
impl PartialEq for ModuleInfoField
Source§fn eq(&self, other: &ModuleInfoField) -> bool
fn eq(&self, other: &ModuleInfoField) -> bool
self and other values to be equal, and is used by ==.impl Copy for ModuleInfoField
impl Eq for ModuleInfoField
impl StructuralPartialEq for ModuleInfoField
Auto Trait Implementations§
impl Freeze for ModuleInfoField
impl RefUnwindSafe for ModuleInfoField
impl Send for ModuleInfoField
impl Sync for ModuleInfoField
impl Unpin for ModuleInfoField
impl UnsafeUnpin for ModuleInfoField
impl UnwindSafe for ModuleInfoField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.