Struct vmap::Error

source ·
pub struct Error { /* private fields */ }
Expand description

A list specifying general categories of map errors.

These errors can be converted into std::io::Error values.

§Examples

fn create_map() -> vmap::Result<vmap::Map> {
    /// ...
}

fn main() -> std::io::Result<()> {
    let map = create_map()?;
    println!("len = {}\n", map.len());
    Ok(())
}

Implementations§

source§

impl Error

source

pub fn io(op: Operation, err: Error) -> Self

Returns an error that wraps a std::io::Error along with an Operation.

§Examples
use std::io::ErrorKind;
use vmap::{Error, Operation};

println!("I/O error: {:?}", Error::io(
    Operation::MapFile,
    ErrorKind::NotFound.into(),
));
source

pub fn input(op: Operation, input: Input) -> Self

Returns an error that wraps an Input type along with an Operation.

§Examples
use vmap::{Error, Operation, Input};

println!("Input error: {:?}", Error::input(
    Operation::MapFile,
    Input::InvalidRange,
));
source

pub fn system(op: Operation, err: Error) -> Self

Returns an error that wraps a system_error::Error along with an Operation.

§Examples
use std::io::ErrorKind;
use vmap::{Error, Operation};

println!("System error: {:?}", Error::system(
    Operation::MapFile,
    system_error::Error::last_os_error()
));
source

pub fn kernel(op: Operation, code: KernelCode) -> Self

Returns an error that wraps a system_error::KernelCode along with an Operation.

§Examples
use vmap::{Error, Operation};

println!("Kernel error: {:?}", Error::kernel(
    Operation::RingAllocate,
    1,
));
source

pub fn last_os_error(op: Operation) -> Self

Returns an error representing the last OS error which occurred.

This function reads the value of errno for the target platform (e.g. GetLastError on Windows) and will return a corresponding instance of Error for the error code.

§Examples
use vmap::{Error, Operation};

println!("last OS error: {:?}", Error::last_os_error(Operation::MapFile));
source

pub fn raw_os_error(&self) -> Option<i32>

Returns the OS error that this error represents (if any).

If this Error was constructed via last_os_error, then this function will return Some, otherwise it will return None.

§Examples
use vmap::{Error, Input, Operation};

fn print_os_error(err: &Error) {
    if let Some(raw_os_err) = err.raw_os_error() {
        println!("raw OS error: {:?}", raw_os_err);
    } else {
        println!("Not an OS error");
    }
}

// Will print "raw OS error: ...".
print_os_error(&Error::last_os_error(Operation::MapFile));
// Will print "Not an OS error".
print_os_error(&Error::input(Operation::MapFile, Input::InvalidRange));
source

pub fn kind(&self) -> ErrorKind

Returns the corresponding std::io::ErrorKind for this error.

§Examples
use std::io::ErrorKind;
use vmap::{Error, Operation};

fn print_error(err: Error) {
    println!("{:?}", err.kind());
}

// Will print "Other".
print_error(Error::last_os_error(Operation::MapFile));
// Will print "NotFound".
print_error(Error::io(Operation::MapFile, ErrorKind::NotFound.into()));
source

pub fn operation(&self) -> Operation

Returns the corresponding Operation that cuased the error.

§Examples
use vmap::{Error, Operation};

fn print_operation(err: Error) {
    println!("{:?}", err.operation());
}

// Will print "MapFile".
print_operation(Error::last_os_error(Operation::MapFile));

Trait Implementations§

source§

impl Debug for Error

source§

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

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

impl Display for Error

source§

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

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

impl Error for Error

source§

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

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<F> From<(Error, F)> for Error

source§

fn from(value: (Error, F)) -> Error

Converts the (Error, F) tuple from a ConvertResult result into an Error, dropping the failed map in the process.

source§

impl From<Error> for Error

source§

fn from(err: Error) -> Self

Converts to this type from the input type.
source§

impl From<Error> for Error

source§

fn from(err: Error) -> Self

Converts to this type from the input type.

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

default 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>,

§

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>,

§

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.