MtpDevice

Struct MtpDevice 

Source
pub struct MtpDevice { /* private fields */ }
Expand description

Result from opening a raw device descriptor, holds information about the device like default folders, battery level, manufacturer, model, storage, etc.

Storage is directly tied to an MTP device by the StoragePool struct abstraction, which you may get with storage_pool after updating the storage with update_storage.

§Example

mtp_device.update_storage().expect("Couldn't update storage");
let storage_pool = mtp_device.storage_pool();

Implementations§

Source§

impl MtpDevice

Source

pub fn default_music_folder(&self) -> u32

Retrieves the default music folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.

Source

pub fn default_playlist_folder(&self) -> u32

Retrieves the default playlist folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.

Source

pub fn default_picture_folder(&self) -> u32

Retrieves the default picture folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.

Source

pub fn default_video_folder(&self) -> u32

Retrieves the default video folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.

Source

pub fn default_organizer_folder(&self) -> u32

Retrieves the default organizer folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.

Source

pub fn default_zencast_folder(&self) -> u32

Retrieves the default zencast folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.

Source

pub fn default_album_folder(&self) -> u32

Retrieves the default album folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.

Source

pub fn default_text_folder(&self) -> u32

Retrieves the default text folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.

Source

pub fn get_friendly_name(&self) -> Result<String>

Gets the friendly name of this device, e.g. “Kevin’s Android”

Source

pub fn set_friendly_name(&self, name: &str) -> Result<()>

Sets the friendly name of this device

Source

pub fn get_sync_partner(&self) -> Result<String>

Retrieves the synchronization partner of this device.

Source

pub fn set_sync_partner(&self, partner: &str) -> Result<()>

Sets the synchronization partner of this device.

Source

pub fn manufacturer_name(&self) -> Result<String>

Returns the manufacturer name of this device.

Source

pub fn model_name(&self) -> Result<String>

Returns the model name of this device.

Source

pub fn serial_number(&self) -> Result<String>

Returns the serial number of this device.

Source

pub fn device_certificate(&self) -> Result<String>

Returns the device (public key) certificate as an XML document string.

Source

pub fn battery_level(&self) -> Result<(BatteryLevel, u8)>

Retrieves the current and maximum battery level of this device.

Source

pub fn secure_time(&self) -> Result<String>

Returns the secure time as an XML document string.

Source

pub fn supported_filetypes(&self) -> Result<Vec<Filetype>>

Retrieves a list of supported file types that this device claims it supports.
This list is mitigated to include the filetypes that libmtp (C library) can handle.

Source

pub fn check_capability(&self, capability: DeviceCapability) -> bool

Check whether this device has some specific capabilitiy.

Source

pub fn reset_device(&self) -> Result<()>

Reset the device only if this one supports the PTP_OC_ResetDevice operation code (0x1010)

Source

pub fn update_storage(&mut self, sort_by: StorageSort) -> Result<UpdateResult>

Updates all the internal storage ids and properties of this device, it can also optionally sort the list. This operation may success, partially success (only ids were retrieved) or fail.

Source

pub fn storage_pool(&self) -> StoragePool<'_>

Returns the inner storage pool, you need to call this if you updated the storage with update_storage. Note that the pool may be empty.

Source

pub fn dump_device_info(&self)

Dumps out a large chunk of textual information provided from the PTP protocol and additionally some extra MTP specific information where applicable.

Source

pub fn is_property_supported( &self, property: Property, filetype: Filetype, ) -> Result<bool>

Determines wheter a property is supported for a given file type.

Source

pub fn allowed_property_values( &self, property: Property, filetype: Filetype, ) -> Result<AllowedValues>

Retrieves the allowes values (range or enumeration) for an specific property.

Source

pub fn dummy_object(&self, id: impl AsObjectId) -> DummyObject<'_>

Build a dummy object, it’s useful to work with objects when we only have an id.

§Example
let id = 30; // stored id
let dummy_object = mtp_device.dummy_object(id);
let string = dummy_object.get_string(Property::ObjectFileName);
Source

pub fn search_file(&self, id: impl AsObjectId) -> Result<File<'_>>

Search for a file with the given id in this device, note that you don’t need to use a Storage for this, since ids are unique across all the device. Don’t call this function repeatedly, the search is O(n)and the call may involve slow USB traffic. Instead use Storage::files_and_folders to cache files.

Trait Implementations§

Source§

impl Debug for MtpDevice

Source§

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

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

impl Drop for MtpDevice

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.