#[non_exhaustive]pub enum Error {
}Expand description
The error type for high-level crate::mtp operations.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NotFound
The object or storage was not found (or never existed).
StaleHandle
A previously-valid handle is no longer valid because the device re-keyed it.
Notably Android’s MediaProvider re-keys object IDs across a media rescan, so a cached handle
can be silently invalidated. The fix is to re-list the parent, re-resolve, and retry once —
not to treat it as a hard not-found. See AGENTS.md.
AccessDenied
The operation was refused: read-only storage, write-protected object, or denied access.
ExclusiveAccess
Another process holds the device exclusively (e.g. ptpcamerad on macOS, or a busy claim).
Use this to guide users to close the conflicting app.
PermissionDenied
The OS denied permission to open the device.
Distinct from Error::ExclusiveAccess: nothing else holds the device — this user/process
lacks permission to access it (most often missing Linux udev rules). Guide the user to fix
device permissions rather than to close another app.
Unsupported
The device does not support this operation.
Busy
The device is temporarily busy; retrying may succeed.
StorageFull
The target storage is full.
Cancelled
The operation was cancelled (via a CancelToken or a stream cancel/drop).
Disconnected
The device was disconnected or stopped responding.
Timeout
The operation timed out.
NoDevice
No matching device was found.
InvalidData
Data received from the device couldn’t be interpreted.
Io
An I/O error not covered by a more specific variant.
Other
A backend error without a more specific neutral mapping.
detail carries backend-specific text (a PTP response code, an HRESULT) for diagnostics
only — don’t pattern-match on its contents.
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 Error::InvalidData with a message.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether retrying the operation might succeed (transient failures).
Sourcepub fn is_exclusive_access(&self) -> bool
pub fn is_exclusive_access(&self) -> bool
Whether another process holds the device exclusively.
Applications can use this to guide users to close the conflicting app (for example, query
IORegistry for UsbExclusiveOwner on macOS).
Sourcepub fn is_permission_denied(&self) -> bool
pub fn is_permission_denied(&self) -> bool
Whether the OS denied permission to access the device (e.g. missing Linux udev rules).
Distinct from is_exclusive_access: the remedy is to fix
device permissions, not to close a conflicting app.
Sourcepub fn is_stale_handle(&self) -> bool
pub fn is_stale_handle(&self) -> bool
Whether this is the Android “re-key” case where re-listing the parent and retrying once is the correct recovery (rather than treating it as not-found).
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · 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()