Trait Object

Source
pub trait Object {
Show 16 methods // Required methods fn id(&self) -> u32; fn device(&self) -> &MtpDevice; // Provided methods fn get_string(&self, property: Property) -> Result<String> { ... } fn set_string(&self, property: Property, string: &str) -> Result<()> { ... } fn get_u64(&self, property: Property) -> Result<u64> { ... } fn get_u32(&self, property: Property) -> Result<u32> { ... } fn set_u32(&self, property: Property, value: u32) -> Result<()> { ... } fn get_u16(&self, property: Property) -> Result<u16> { ... } fn set_u16(&self, property: Property, value: u16) -> Result<()> { ... } fn get_u8(&self, property: Property) -> Result<u8> { ... } fn set_u8(&self, property: Property, value: u8) -> Result<()> { ... } fn delete(&self) -> Result<()> { ... } fn move_to(&self, storage_id: u32, parent: Parent) -> Result<()> { ... } fn copy_to(&self, storage_id: u32, parent: Parent) -> Result<()> { ... } fn get_partial_object(&self, offset: u64, maxbytes: u32) -> Result<Vec<u8>> { ... } fn send_partial_object( &self, offset: u64, data: impl AsRef<[u8]>, ) -> Result<()> { ... }
}
Expand description

Common behavior of many higher abstractions is grouped in this trait, basically everything on MTP is an object with some attributes, even though this API is exposed, it’s not recommended to use it to modify or get attributes that can be managed with other specefic APIs (like files, folders, tracks, etc).

Required Methods§

Source

fn id(&self) -> u32

Must return the id of the object.

Source

fn device(&self) -> &MtpDevice

Must return a valid reference of an MtpDevice, where this object resides in.

Provided Methods§

Source

fn get_string(&self, property: Property) -> Result<String>

Retrieves a string from an object attribute.

Source

fn set_string(&self, property: Property, string: &str) -> Result<()>

Sets an object attribute from a string.

Source

fn get_u64(&self, property: Property) -> Result<u64>

Retrieves an u64 from an object attribute.

Source

fn get_u32(&self, property: Property) -> Result<u32>

Retrieves an u32 from an object attribute, returns the value of default on failure.

Source

fn set_u32(&self, property: Property, value: u32) -> Result<()>

Sets an object attribute from an u32.

Source

fn get_u16(&self, property: Property) -> Result<u16>

Retrieves an u16 from an object attribute, returns the value of default on failure.

Source

fn set_u16(&self, property: Property, value: u16) -> Result<()>

Sets an object attribute from an u16.

Source

fn get_u8(&self, property: Property) -> Result<u8>

Retrieves an u8 from an object attribute, returns the value of default on failure.

Source

fn set_u8(&self, property: Property, value: u8) -> Result<()>

Sets an object attribute from an u8.

Source

fn delete(&self) -> Result<()>

Deletes a single file, track, playlist, folder or any other object off the MTP device. Note that deleting folders may no be remove its contents, in turn this is the expected behavior.

If you want to delete a folder first recursively delete all files and folders contained in this folder, then the folder itself. Finally, if the operation is sucessful you should discard the object given that now it holds an invalid id.

Source

fn move_to(&self, storage_id: u32, parent: Parent) -> Result<()>

Moves the object to the specified storage (by its id) and parent folder. Moving objects may or not be supported on the device.

Note that moving an object may take a significant amount of time, particularly if being moved between storages, MTP doesn’t provide any kind of progress mechanism, so the operation will simply block for the duration.

Source

fn copy_to(&self, storage_id: u32, parent: Parent) -> Result<()>

Copies the object to the specified storage (by its id) and parent folder. Copying objects may or not be supported on the device.

Note that copying an object may take a significant amount of time, particularly if being copied between storages, MTP doesn’t provide any kind of progress mechanism, so the operation will simply block for the duration.

Source

fn get_partial_object(&self, offset: u64, maxbytes: u32) -> Result<Vec<u8>>

Get partial data from an object, specifying an offset and the maximum bytes that should be read. Note that this may return fewer bytes than the maximum.

Source

fn send_partial_object(&self, offset: u64, data: impl AsRef<[u8]>) -> Result<()>

Send partial data to an object, specifying an offset and the data you want to write into the object.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Object for &File<'_>

Source§

impl Object for &Folder<'_>

Source§

impl Object for File<'_>

Source§

impl Object for Folder<'_>

Source§

impl Object for DummyObject<'_>