Skip to main content

usb_if/
err.rs

1use alloc::{boxed::Box, string::String};
2
3#[derive(thiserror::Error, Debug)]
4pub enum TransferError {
5    #[error("Stall")]
6    Stall,
7    #[error("Request queue full")]
8    RequestQueueFull,
9    #[error("Timeout")]
10    Timeout,
11    #[error("Cancelled")]
12    Cancelled,
13    #[error("Other error: {0}")]
14    Other(#[from] anyhow::Error),
15}
16
17impl From<Box<dyn core::error::Error>> for TransferError {
18    fn from(err: Box<dyn core::error::Error>) -> Self {
19        TransferError::Other(anyhow::anyhow!("{}", err))
20    }
21}
22
23#[derive(thiserror::Error, Debug)]
24pub enum USBError {
25    #[error("Timeout")]
26    Timeout,
27    #[error("No memory available")]
28    NoMemory,
29    #[error("Transfer error: {0}")]
30    TransferError(#[from] TransferError),
31    #[error("Not initialized")]
32    NotInitialized,
33    #[error("Not found")]
34    NotFound,
35    #[error("Invalid parameter")]
36    InvalidParameter,
37    #[error("Slot limit reached")]
38    SlotLimitReached,
39    #[error("Configuration not set")]
40    ConfigurationNotSet,
41    #[error("Not supported")]
42    NotSupported,
43    #[error("Other error: {0}")]
44    Other(#[from] anyhow::Error),
45}
46
47impl From<&str> for USBError {
48    fn from(value: &str) -> Self {
49        USBError::Other(anyhow::anyhow!("{value}"))
50    }
51}
52
53impl From<String> for USBError {
54    fn from(value: String) -> Self {
55        USBError::Other(anyhow::anyhow!(value))
56    }
57}
58
59/*
60
61LIBUSB_SUCCESS
62Success (no error)
63
64LIBUSB_ERROR_IO
65Input/output error.
66
67LIBUSB_ERROR_INVALID_PARAM
68Invalid parameter.
69
70LIBUSB_ERROR_ACCESS
71Access denied (insufficient permissions)
72
73LIBUSB_ERROR_NO_DEVICE
74No such device (it may have been disconnected)
75
76LIBUSB_ERROR_NOT_FOUND
77Entity not found.
78
79LIBUSB_ERROR_BUSY
80Resource busy.
81
82LIBUSB_ERROR_TIMEOUT
83Operation timed out.
84
85LIBUSB_ERROR_OVERFLOW
86Overflow.
87
88LIBUSB_ERROR_PIPE
89Pipe error.
90
91LIBUSB_ERROR_INTERRUPTED
92System call interrupted (perhaps due to signal)
93
94LIBUSB_ERROR_NO_MEM
95Insufficient memory.
96
97LIBUSB_ERROR_NOT_SUPPORTED
98Operation not supported or unimplemented on this platform.
99
100LIBUSB_ERROR_OTHER
101Other error.
102*/