pub enum Error {
Usb(Error),
Protocol {
code: ResponseCode,
operation: OperationCode,
},
InvalidData {
message: String,
},
Io(Error),
Timeout,
Disconnected,
SessionNotOpen,
NoDevice,
Cancelled,
}Expand description
The main error type for mtp-rs operations.
Variants§
Usb(Error)
USB communication error
Protocol
Protocol-level error from device
Fields
code: ResponseCodeThe response code returned by the device.
operation: OperationCodeThe operation that triggered the error.
InvalidData
Invalid data received from device
Io(Error)
I/O error
Timeout
Operation timed out
Disconnected
Device was disconnected
SessionNotOpen
Session not open
NoDevice
No device found
Cancelled
Operation cancelled
Implementations§
Source§impl Error
impl Error
Sourcepub fn invalid_data(message: impl Into<String>) -> Self
pub fn invalid_data(message: impl Into<String>) -> Self
Create an invalid data error with a message.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Check if this is a retryable error.
Retryable errors are transient and the operation may succeed if retried:
DeviceBusy: Device is temporarily busyTimeout: Operation timed out but device may still be responsive
Sourcepub fn response_code(&self) -> Option<ResponseCode>
pub fn response_code(&self) -> Option<ResponseCode>
Get the response code if this is a protocol error.
Sourcepub fn is_exclusive_access(&self) -> bool
pub fn is_exclusive_access(&self) -> bool
Check if this error indicates another process has exclusive access to the device.
This typically happens on macOS when ptpcamerad or another application
has already claimed the USB interface. Applications can use this to provide
platform-specific guidance to users.
§Example
match device.open().await {
Err(e) if e.is_exclusive_access() => {
// On macOS, likely ptpcamerad interference
// App can query IORegistry for UsbExclusiveOwner to get details
show_exclusive_access_help();
}
Err(e) => handle_other_error(e),
Ok(dev) => use_device(dev),
}Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()