Skip to main content

Error

Enum Error 

Source
pub enum Error<'a> {
Show 20 variants OutOfMemory, QueueSendTimeout, QueueReceiveTimeout, MutexTimeout, MutexLockFailed, Timeout, QueueFull, StringConversionError, TaskNotFound, InvalidQueueSize, NullPtr, NotFound, OutOfIndex, InvalidType, Empty, WriteError(&'a str), ReadError(&'a str), ReturnWithCode(i32), Unhandled(&'a str), UnhandledOwned(String),
}
Expand description

Error types for OSAL-RS operations.

Represents all possible error conditions that can occur when using the OSAL-RS library.

§Lifetime Parameter

The error type is generic over lifetime 'a to allow flexible error messages. Most of the time, you can use the default Result<T> type alias which uses Error<'static>. For custom lifetimes in error messages, use core::result::Result<T, Error<'a>> explicitly.

§Examples

§Basic usage with static errors

use osal_rs::os::{Queue, QueueFn};
use osal_rs::utils::Error;
 
match Queue::new(10, 32) {
    Ok(queue) => { /* use queue */ },
    Err(Error::OutOfMemory) => println!("Failed to allocate queue"),
    Err(e) => println!("Other error: {:?}", e),
}

§Using borrowed error messages

use osal_rs::utils::Error;
 
fn validate_input(input: &str) -> core::result::Result<(), Error> {
    if input.is_empty() {
        // Use static lifetime for compile-time strings
        Err(Error::Unhandled("Input cannot be empty"))
    } else {
        Ok(())
    }
}
 
// For dynamic error messages from borrowed data
fn process_data<'a>(data: &'a str) -> core::result::Result<(), Error<'a>> {
    if !data.starts_with("valid:") {
        // Error message borrows from 'data' lifetime
        Err(Error::ReadError(data))
    } else {
        Ok(())
    }
}

Variants§

§

OutOfMemory

Insufficient memory to complete operation

§

QueueSendTimeout

Queue send operation timed out

§

QueueReceiveTimeout

Queue receive operation timed out

§

MutexTimeout

Mutex operation timed out

§

MutexLockFailed

Failed to acquire mutex lock

§

Timeout

Generic timeout error

§

QueueFull

Queue is full and cannot accept more items

§

StringConversionError

String conversion failed

§

TaskNotFound

Thread/task not found

§

InvalidQueueSize

Invalid queue size specified

§

NullPtr

Null pointer encountered

§

NotFound

Requested item not found

§

OutOfIndex

Index out of bounds

§

InvalidType

Invalid type for operation

§

Empty

No data available

§

WriteError(&'a str)

Write error occurred

§

ReadError(&'a str)

Read error occurred

§

ReturnWithCode(i32)

Return error with code

§

Unhandled(&'a str)

Unhandled error with description

§

UnhandledOwned(String)

Unhandled error with description owned

Trait Implementations§

Source§

impl<'a> Clone for Error<'a>

Source§

fn clone(&self) -> Error<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Error<'a>

Source§

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

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

impl<'a> Display for Error<'a>

Source§

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

Formats the error for display.

Provides human-readable error messages suitable for logging or presentation to users.

Source§

impl<'a> Eq for Error<'a>

Source§

impl<'a> Error for Error<'a>

Implements the standard Error trait for Error<'a>. This allows Error<'a> to be used with Rust’s error handling ecosystem, including Result and ? operator.

§Examples

§Using ? with the crate’s Result alias
use osal_rs::utils::{Error, Result};

fn parse_level(input: &str) -> Result<u8> {
    input.parse::<u8>().map_err(|_| Error::StringConversionError)
}

fn set_level(input: &str) -> Result<()> {
    // `?` propagates `Error` because it implements `core::error::Error`
    let level = parse_level(input)?;
    assert!(level <= 255);
    Ok(())
}

assert!(set_level("42").is_ok());
assert_eq!(set_level("abc"), Err(Error::StringConversionError));
§Boxing into a dyn Error
extern crate alloc;
use alloc::boxed::Box;
use osal_rs::utils::Error;

fn fallible() -> core::result::Result<(), Box<dyn core::error::Error>> {
    // `Error<'static>` converts into `Box<dyn Error>` automatically
    Err(Error::Timeout)?;
    Ok(())
}

let err = fallible().unwrap_err();
assert_eq!(err.to_string(), "Operation timeout");
§Inspecting the error source chain
use core::error::Error as _;
use osal_rs::utils::Error;

let err = Error::Unhandled("sensor offline");
// `Error` has no underlying cause, so `source()` is `None`
assert!(err.source().is_none());
assert_eq!(err.to_string(), "Unhandled error: sensor offline");
1.30.0 · 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 Error<'static>

Available on crate feature posix only.

Converts a std::io::Error into an Error<'static>. This is useful for integrating standard I/O errors with the crate’s error handling system.

The resulting variant is always Error::UnhandledOwned, with the message prefixed by io error: .

§Examples

§Propagating I/O errors with ?
use osal_rs::utils::Result;

fn read_config(path: &str) -> Result<String> {
    // `std::io::Error` is converted into `Error<'static>` by `?`
    let content = std::fs::read_to_string(path)?;
    Ok(content)
}

let err = read_config("/this/path/does/not/exist").unwrap_err();
assert!(err.to_string().starts_with("Unhandled error owned: io error: "));
§Explicit conversion and pattern matching
use std::io;
use osal_rs::utils::Error;

let io_err = io::Error::new(io::ErrorKind::PermissionDenied, "access denied");
let err: Error = io_err.into();

match err {
    Error::UnhandledOwned(msg) => assert_eq!(msg, "io error: access denied"),
    other => panic!("unexpected variant: {other:?}"),
}
Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl<'a> Hash for Error<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for Error<'a>

Source§

fn eq(&self, other: &Error<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Error<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Error<'a>

§

impl<'a> RefUnwindSafe for Error<'a>

§

impl<'a> Send for Error<'a>

§

impl<'a> Sync for Error<'a>

§

impl<'a> Unpin for Error<'a>

§

impl<'a> UnsafeUnpin for Error<'a>

§

impl<'a> UnwindSafe for Error<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.