Skip to main content

ModuleInfoError

Enum ModuleInfoError 

Source
#[non_exhaustive]
pub enum ModuleInfoError { NotAvailable(String), NullPointer, Utf8Error(Utf8Error), MalformedJson(String), MetadataTooLarge(String), IoError(Error), Other(Box<dyn Error + Send + Sync>), }
Expand description

Errors returned from module_info APIs.

#[non_exhaustive]: new variants may land in minor releases. Any match on this enum from outside the crate needs a wildcard arm or it will fail to compile when a variant is added.

§Example

use module_info::{ModuleInfoError, ModuleInfoResult};

// A function that might return a ModuleInfoError
fn get_module_name() -> ModuleInfoResult<String> {
    Err(ModuleInfoError::NotAvailable("example".to_string()))
}

match get_module_name() {
    Ok(name) => println!("Module name: {name}"),
    Err(ModuleInfoError::NotAvailable(msg)) => eprintln!("not available: {msg}"),
    Err(ModuleInfoError::NullPointer) => eprintln!("null pointer"),
    Err(ModuleInfoError::MalformedJson(msg)) => eprintln!("malformed JSON: {msg}"),
    Err(e) => eprintln!("other error: {e}"),
}

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.
§

NotAvailable(String)

Module info is unavailable: either the embed-module-info feature is off or the target is not Linux. The contained string carries context.

§

NullPointer

A null pointer was passed to extract_module_info. Typically means the linker script did not run or the .note.package section was stripped from the binary.

§

Utf8Error(Utf8Error)

The embedded bytes were not valid UTF-8.

§

MalformedJson(String)

The embedded JSON could not be parsed, a required field is missing or empty, or moduleVersion is not four u16-sized parts. The contained string identifies the specific failure.

§

MetadataTooLarge(String)

The serialized metadata JSON exceeded MAX_JSON_SIZE (1 KiB) at build time. The contained string reports the actual vs. allowed size.

§

IoError(Error)

I/O failure while reading Cargo.toml or writing the generated linker script and JSON dump from build.rs.

§

Other(Box<dyn Error + Send + Sync>)

Catch-all for errors that do not fit the variants above. Holds the originating error for source() chaining.

Trait Implementations§

Source§

impl Debug for ModuleInfoError

Source§

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

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

impl Display for ModuleInfoError

Source§

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

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

impl Error for ModuleInfoError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for ModuleInfoError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for ModuleInfoError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for ModuleInfoError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Utf8Error> for ModuleInfoError

Source§

fn from(err: Utf8Error) -> Self

Converts to this type from the input type.
Source§

impl From<VarError> for ModuleInfoError

Source§

fn from(err: VarError) -> Self

Converts to this type from the input type.

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.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.