Skip to main content

Crate mtp_rs

Crate mtp_rs 

Source
Expand description

§mtp-rs

A pure-Rust MTP (Media Transfer Protocol) library targeting modern Android devices.

§Features

  • Runtime agnostic: Uses futures traits, works with any async runtime
  • Two-level API: High-level mtp:: for media devices, low-level ptp:: for cameras
  • Streaming: Memory-efficient streaming downloads with progress tracking
  • Type safe: Newtype wrappers prevent mixing up IDs

§Quick start

use mtp_rs::mtp::MtpDevice;

// Open the first MTP device
let device = MtpDevice::open_first().await?;

println!("Connected to: {} {}",
         device.device_info().manufacturer,
         device.device_info().model);

// Get storages
for storage in device.storages().await? {
    println!("Storage: {} ({} free)",
             storage.info().description,
             storage.info().free_space);

    // List root folder
    for obj in storage.list_objects(None).await? {
        let kind = if obj.is_folder() { "DIR " } else { "FILE" };
        println!("  {} {} ({} bytes)", kind, obj.filename, obj.size);
    }
}

§Stability

SemVer covers what the crate root re-exports, plus mtp and ptp. These optional features are exempt from it, so they can change in any release:

  • unstable-raw: transport:: and the other nusb-typed items, for when you enumerate with nusb yourself or bring your own transport. Listing devices and opening by serial or location need no raw types.
  • virtual-device: virtual_device::, a filesystem-backed device for testing without hardware.
  • tracing: structured diagnostics. The event names and fields can change, as can log output.

Re-exports§

pub use mtp::Error;
pub use mtp::UploadError;
pub use mtp::watch_devices;
pub use mtp::Backend;
pub use mtp::ByteRange;
pub use mtp::Capabilities;
pub use mtp::DateTime;
pub use mtp::DeviceEvent;
pub use mtp::DeviceInfo;
pub use mtp::DeviceWatch;
pub use mtp::DeviceWatchBuilder;
pub use mtp::FileDownload;
pub use mtp::FilesystemType;
pub use mtp::HotplugEvent;
pub use mtp::ListingItem;
pub use mtp::MtpDevice;
pub use mtp::MtpDeviceBuilder;
pub use mtp::MtpDeviceInfo;
pub use mtp::NewObjectInfo;
pub use mtp::ObjectCollection;
pub use mtp::ObjectFormat;
pub use mtp::ObjectHandle;
pub use mtp::ObjectInfo;
pub use mtp::ObjectListing;
pub use mtp::Progress;
pub use mtp::SkippedObject;
pub use mtp::Storage;
pub use mtp::StorageId;
pub use mtp::StorageInfo;
pub use mtp::StorageType;
pub use mtp::UtcOffset;
pub use mtp::WindowedDownload;
pub use mtp::DEFAULT_CANCEL_TIMEOUT;
pub use mtp::DEFAULT_DOWNLOAD_WINDOW;
pub use mtp::DEFAULT_SETTLE_DELAY;
pub use mtp::MAX_NAME_UNITS;
pub use transport::MtpMatchReason;
pub use transport::UsbSpeed;

Modules§

mtp
High-level MTP (Media Transfer Protocol) API for Android devices and media players.
ptp
Low-level PTP (Picture Transfer Protocol) implementation.
transport
USB transport abstraction layer. Exempt from SemVer.
virtual_device
A filesystem-backed virtual MTP device, for testing without hardware. Exempt from SemVer.

Structs§

CancelToken
Cooperative cancellation handle for long-running MTP operations.