pub struct Storage<'a> { /* private fields */ }
Expand description
Storage descriptor of some MTP device, note that updating the storage and keeping a old copy of this struct is impossible.
Implementations§
Source§impl<'a> Storage<'a>
impl<'a> Storage<'a>
Sourcepub fn storage_type(&self) -> StorageType
pub fn storage_type(&self) -> StorageType
Returns the storage type
Sourcepub fn filesystem_type(&self) -> FilesystemType
pub fn filesystem_type(&self) -> FilesystemType
Returns the file system type
Sourcepub fn access_capability(&self) -> AccessCapability
pub fn access_capability(&self) -> AccessCapability
Returns the access capability
Sourcepub fn maximum_capacity(&self) -> u64
pub fn maximum_capacity(&self) -> u64
Returns the maximum capacity
Sourcepub fn free_space_in_bytes(&self) -> u64
pub fn free_space_in_bytes(&self) -> u64
Returns the free space in bytes
Sourcepub fn free_space_in_objects(&self) -> u64
pub fn free_space_in_objects(&self) -> u64
Returns the free space in objects
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
Returns the storage description
Sourcepub fn volume_identifier(&self) -> Option<&str>
pub fn volume_identifier(&self) -> Option<&str>
Returns the volume identifier
Sourcepub fn format_storage(&self) -> Result<()>
pub fn format_storage(&self) -> Result<()>
Formats this storage (if its device supports the operation).
WARNING: This WILL DELETE ALL DATA from the device, make sure you’ve got confirmation from the user before calling this function.
Sourcepub fn files_and_folders(&self, parent: Parent) -> Vec<File<'a>>
pub fn files_and_folders(&self, parent: Parent) -> Vec<File<'a>>
Retrieves the contents of a certain folder (parent
) in this storage, the result contains
both files and folders, note that this request will always perform I/O with the device.
Sourcepub fn folder_list(&self) -> Option<Folder<'a>>
pub fn folder_list(&self) -> Option<Folder<'a>>
Optionally returns a Folder
, with this struct you can build a tree
structure (see Folder
for more info)
Sourcepub fn create_folder<'b>(
&self,
name: &'b str,
parent: Parent,
) -> Result<(u32, Cow<'b, str>)>
pub fn create_folder<'b>( &self, name: &'b str, parent: Parent, ) -> Result<(u32, Cow<'b, str>)>
Tries to create a new folder in this storage for 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.
Sourcepub fn get_file_to_path(
&self,
file: impl AsObjectId,
path: impl AsRef<Path>,
) -> Result<()>
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.
Sourcepub fn get_file_to_path_with_callback<C>(
&self,
file: impl AsObjectId,
path: impl AsRef<Path>,
callback: C,
) -> Result<()>
pub fn get_file_to_path_with_callback<C>( &self, file: impl AsObjectId, path: impl AsRef<Path>, callback: C, ) -> 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.
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
.
Sourcepub fn get_file_to_descriptor(
&self,
file: impl AsObjectId,
descriptor: impl AsRawFd,
) -> Result<()>
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.
Sourcepub fn get_file_to_descriptor_with_callback<C>(
&self,
file: impl AsObjectId,
descriptor: impl AsRawFd,
callback: C,
) -> Result<()>
pub fn get_file_to_descriptor_with_callback<C>( &self, file: impl AsObjectId, descriptor: impl AsRawFd, callback: C, ) -> 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.
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
.
Sourcepub fn get_file_to_handler<H>(
&self,
file: impl AsObjectId,
handler: H,
) -> Result<()>
pub fn get_file_to_handler<H>( &self, file: impl AsObjectId, handler: H, ) -> Result<()>
Retrieves a file from the device storage and calls handler with chunks of data. Note
that get_file_to_descriptor
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
.
Sourcepub fn get_file_to_handler_with_callback<H, C>(
&self,
file: impl AsObjectId,
handler: H,
callback: C,
) -> Result<()>
pub fn get_file_to_handler_with_callback<H, C>( &self, file: impl AsObjectId, handler: H, callback: C, ) -> Result<()>
Retrieves a file from the device storage and calls handler with chunks of data. Note
that get_file_to_descriptor
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
.
Sourcepub fn send_file_from_path<C>(
&self,
path: impl AsRef<Path>,
parent: Parent,
metadata: FileMetadata<'_>,
) -> Result<File<'a>>
pub fn send_file_from_path<C>( &self, path: impl AsRef<Path>, parent: Parent, metadata: FileMetadata<'_>, ) -> Result<File<'a>>
Sends a local file to the MTP device who this storage belongs to.
Sourcepub fn send_file_from_path_with_callback<C>(
&self,
path: impl AsRef<Path>,
parent: Parent,
metadata: FileMetadata<'_>,
callback: C,
) -> Result<File<'a>>
pub fn send_file_from_path_with_callback<C>( &self, path: impl AsRef<Path>, parent: Parent, metadata: FileMetadata<'_>, callback: C, ) -> Result<File<'a>>
Sends a local file to the MTP device who this storage belongs to.
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
.
Sourcepub fn send_file_from_descriptor(
&self,
descriptor: impl AsRawFd,
parent: Parent,
metadata: FileMetadata<'_>,
) -> Result<File<'a>>
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.
Sourcepub fn send_file_from_descriptor_with_callback<C>(
&self,
descriptor: impl AsRawFd,
parent: Parent,
metadata: FileMetadata<'_>,
callback: C,
) -> Result<File<'a>>
pub fn send_file_from_descriptor_with_callback<C>( &self, descriptor: impl AsRawFd, parent: Parent, metadata: FileMetadata<'_>, callback: C, ) -> Result<File<'a>>
Sends a local file via descriptor to the MTP device who this storage belongs to.
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
.
Sourcepub fn send_file_from_handler<H>(
&self,
handler: H,
parent: Parent,
metadata: FileMetadata<'_>,
) -> Result<File<'a>>
pub fn send_file_from_handler<H>( &self, handler: H, parent: Parent, metadata: FileMetadata<'_>, ) -> Result<File<'a>>
Sends a bunch of data to the MTP device who this storage belongs to.
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
.
Sourcepub fn send_file_from_handler_with_callback<H, C>(
&self,
handler: H,
parent: Parent,
metadata: FileMetadata<'_>,
callback: C,
) -> Result<File<'a>>
pub fn send_file_from_handler_with_callback<H, C>( &self, handler: H, parent: Parent, metadata: FileMetadata<'_>, callback: C, ) -> Result<File<'a>>
Sends a bunch of data to the MTP device who this storage belongs to.
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
.