Struct StoragePool

Source
pub struct StoragePool<'a> { /* private fields */ }
Expand description

Represents all the storage “pool” of one MTP device, contain all the storage entries of one MTP device, and contains some methods to send or get files from the primary storage.

Implementations§

Source§

impl<'a> StoragePool<'a>

Source

pub fn device(&self) -> &MtpDevice

Returns the MtpDevice that owns this storage pool

Source

pub fn by_id(&self, id: u32) -> Option<&Storage<'a>>

Returns the storage that has the given id, if there’s one.

Source

pub fn iter(&'a self) -> StoragePoolIter<'a>

Returns an iterator over the storages, this is a HashMap iterator.

Source

pub fn files_and_folders(&self, parent: Parent) -> Vec<File<'a>>

Retrieves the contents of a certain folder (parent) in all storages, the result contains both files and folders, note that this request will always perform I/O with the device.

Source

pub fn folder_list(&self) -> Option<Folder<'_>>

Optionally returns a Folder, with this struct you can build a tree structure (see Folder for more info)

Source

pub fn create_folder<'b>( &self, name: &'b str, parent: Parent, ) -> Result<(u32, Cow<'b, str>)>

Tries to create a new folder in the default storage of the relevant MtpDevice, returns the id of the new folder and its name, note that the name may be different due to device file system restrictions.

Source

pub fn get_file_to_path( &self, file: impl AsObjectId, path: impl AsRef<Path>, ) -> Result<()>

Retrieves a file from the device storage to a local file identified by a filename. Note that get_file_to_path on Storage and StoragePool are semantically the same because objects have unique ids across all the device.

Source

pub fn get_file_to_path_with_callback<C>( &self, file: impl AsObjectId, path: impl AsRef<Path>, callback: C, ) -> Result<()>
where C: FnMut(u64, u64) -> CallbackReturn,

Retrieves a file from the device storage to a local file identified by a filename. Note that get_file_to_path on Storage and StoragePool are semantically the same because objects have unique ids across all the device.

The callback parameter is a progress function with the following signature (sent_bytes: u64, total_bytes: u64) -> CallbackReturn, this way you can check the progress and if you want to cancel operation you just return CallbackReturn::Cancel.

Source

pub fn get_file_to_descriptor( &self, file: impl AsObjectId, descriptor: impl AsRawFd, ) -> Result<()>

Retrieves a file from the device storage to a local file identified by a descriptor. Note that get_file_to_descriptor on Storage and StoragePool are semantically the same because objects have unique ids across all the device.

Source

pub fn get_file_to_descriptor_with_callback<C>( &self, file: impl AsObjectId, descriptor: impl AsRawFd, callback: C, ) -> Result<()>
where C: FnMut(u64, u64) -> CallbackReturn,

Retrieves a file from the device storage to a local file identified by a descriptor. Note that get_file_to_descriptor on Storage and StoragePool are semantically the same because objects have unique ids across all the device.

The callback parameter is a progress function with the following signature (sent_bytes: u64, total_bytes: u64) -> CallbackReturn, this way you can check the progress and if you want to cancel operation you just return CallbackReturn::Cancel.

Source

pub fn get_file_to_handler<H>( &self, file: impl AsObjectId, handler: H, ) -> Result<()>
where H: FnMut(&[u8]) -> HandlerReturn,

Retrieves a file from the device storage and calls handler with chunks of data. Note that get_file_to_handler on Storage and StoragePool are semantically the same because objects have unique ids across all the device.

The handler parameter is a function that receives the chunks of data with the following signature (data: &[u8]) -> HandlerReturn, you should return HandlerReturn::Ok(readed_bytes) if there weren’t errors with the amount of bytes you read from data.

Source

pub fn get_file_to_handler_with_callback<H, C>( &self, file: impl AsObjectId, handler: H, callback: C, ) -> Result<()>
where H: FnMut(&[u8]) -> HandlerReturn, C: FnMut(u64, u64) -> CallbackReturn,

Retrieves a file from the device storage and calls handler with chunks of data. Note that get_file_to_handler on Storage and StoragePool are semantically the same because objects have unique ids across all the device.

The handler parameter is a function that receives the chunks of data with the following signature (data: &[u8]) -> HandlerReturn, you should return HandlerReturn::Ok(readed_bytes) if there weren’t errors with the amount of bytes you read from data.

The callback parameter is a progress function with the following signature (sent_bytes: u64, total_bytes: u64) -> CallbackReturn, this way you can check the progress and if you want to cancel operation you just return CallbackReturn::Cancel.

Source

pub fn send_file_from_path<C>( &self, path: impl AsRef<Path>, parent: Parent, metadata: FileMetadata<'_>, ) -> Result<File<'a>>
where C: FnMut(u64, u64) -> CallbackReturn,

Sends a local file to the MTP device who this storage belongs to, note that this method will send the file to the primary storage.

Source

pub fn send_file_from_path_with_callback<C>( &self, path: impl AsRef<Path>, parent: Parent, metadata: FileMetadata<'_>, callback: C, ) -> Result<File<'a>>
where C: FnMut(u64, u64) -> CallbackReturn,

Sends a local file to the MTP device who this storage belongs to, note that this method will send the file to the primary storage.

The callback parameter is a progress function with the following signature (sent_bytes: u64, total_bytes: u64) -> CallbackReturn, this way you can check the progress and if you want to cancel operation you just return CallbackReturn::Cancel.

Source

pub fn send_file_from_descriptor( &self, descriptor: impl AsRawFd, parent: Parent, metadata: FileMetadata<'_>, ) -> Result<File<'a>>

Sends a local file via descriptor to the MTP device who this storage belongs to, note that this method will send the file to the primary storage.

Source

pub fn send_file_from_descriptor_with_callback<C>( &self, descriptor: impl AsRawFd, parent: Parent, metadata: FileMetadata<'_>, callback: C, ) -> Result<File<'a>>
where C: FnMut(u64, u64) -> CallbackReturn,

Sends a local file via descriptor to the MTP device who this storage belongs to, note that this method will send the file to the primary storage.

The callback parameter is a progress function with the following signature (sent_bytes: u64, total_bytes: u64) -> CallbackReturn, this way you can check the progress and if you want to cancel operation you just return CallbackReturn::Cancel.

Source

pub fn send_file_from_handler<H>( &self, handler: H, parent: Parent, metadata: FileMetadata<'_>, ) -> Result<File<'a>>
where H: FnMut(&mut [u8]) -> HandlerReturn,

Sends a bunch of data to the MTP device who this storage belongs to, note that this method will send the file to primary storage.

The handler parameter is a function that gives you a chunk to write data with the following signature (data: &mut [u8]) -> HandlerReturn, you should return HandlerReturn::Ok(written_bytes) if there weren’t errors with the amount of bytes you wrote to data.

Source

pub fn send_file_from_handler_with_callback<H, C>( &self, handler: H, parent: Parent, metadata: FileMetadata<'_>, callback: C, ) -> Result<File<'a>>
where H: FnMut(&mut [u8]) -> HandlerReturn, C: FnMut(u64, u64) -> CallbackReturn,

Sends a bunch of data to the MTP device who this storage belongs to, note that this method will send the file to primary storage.

The handler parameter is a function that gives you a chunk to write data with the following signature (data: &mut [u8]) -> HandlerReturn, you should return HandlerReturn::Ok(written_bytes) if there weren’t errors with the amount of bytes you wrote to data.

The callback parameter is a progress function with the following signature (sent_bytes: u64, total_bytes: u64) -> CallbackReturn, this way you can check the progress and if you want to cancel operation you just return CallbackReturn::Cancel.

Trait Implementations§

Source§

impl<'a> Debug for StoragePool<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for StoragePool<'a>

§

impl<'a> RefUnwindSafe for StoragePool<'a>

§

impl<'a> !Send for StoragePool<'a>

§

impl<'a> !Sync for StoragePool<'a>

§

impl<'a> Unpin for StoragePool<'a>

§

impl<'a> UnwindSafe for StoragePool<'a>

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.