pub enum Error {
    Usage,
    ExitCode(c_int),
    GenericError(Box<dyn Error>),
}
Expand description

The error type for Builtin::call.

Usually, you don’t need to construct this type manually. Instead, use the ? operator for any Result in the body of the Builtin::call method, and errors will be converted to this type.

However, if you want to return a specific exit code, use the ExitCode variant.

Variants

Usage

Syntax error in usage.

ExitCode(c_int)

Exit with a specific code.

Example

use bash_builtins::{Args, Builtin, Error::ExitCode, Result};

impl Builtin for SomeName {
    fn call(&mut self, args: &mut Args) -> Result<()> {
        // In this builtin, we return `127` if there are
        // no arguments.
        if args.is_empty() {
            return Err(ExitCode(127));
        }

        // …

        Ok(())
    }
}

GenericError(Box<dyn Error>)

Wrapper for any error.

This variant is used when the builtin propagates any error inside Builtin::call.

Example

use std::fs;
use bash_builtins::{Args, Builtin, Error::ExitCode, Result};

impl Builtin for SomeName {
    fn call(&mut self, args: &mut Args) -> Result<()> {

        // fs::read can return an `io::Error`, which is wrapped
        // by `GenericError` and then used as the return value.
        let _ = fs::read("/some/config/file")?;

        // …

        Ok(())
    }
}

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.