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§
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl !Send for Error
impl !Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
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
Mutably borrows from an owned value. Read more