Skip to main content

print_module_info

Function print_module_info 

Source
pub fn print_module_info() -> ModuleInfoResult<()>
Expand description

Prints all available module info to stdout and returns a result indicating success or failure

This utility function retrieves all embedded module information and outputs it to the console with labels. It’s useful for debugging or displaying version information in command-line tools.

§Examples

Basic usage with simple error handling:

if module_info::print_module_info().is_ok() {
    println!("Module info displayed successfully");
}

Error handling:

use module_info::{print_module_info, ModuleInfoError};

match print_module_info() {
    Ok(_) => println!("Module info displayed successfully"),
    Err(ModuleInfoError::NotAvailable(msg)) => eprintln!("Module info not available: {}", msg),
    Err(e) => eprintln!("Failed to display module info: {}", e),
}

§Errors

This function will return an error in the following situations:

  • If any of the seven required identity-plus-platform fields (binary, version, moduleVersion, name, maintainer, os, osVersion) is missing or empty, suggesting the metadata is missing or corrupted (returns ModuleInfoError::NotAvailable)
  • If running on a non-Linux platform where module info isn’t supported (returns ModuleInfoError::NotAvailable)

§Note

This function is only available when the “embed-module-info” feature is enabled and the target OS is Linux. On other platforms the function exists as a no-op stub that returns NotAvailable, matching the non-Linux get_module_info! macro behavior so cross-platform callers compile unchanged.