use crate::device::session::MtpSession;
use crate::device::storage::{AccessCapability, FilesystemType, StorageId, StorageType};
use crate::device::{Device, PtpIo};
use crate::error::MtpError;
pub struct Storage {
pub id: StorageId,
pub ty: StorageType,
pub filesystem_type: FilesystemType,
pub access_capability: AccessCapability,
pub max_capacity: u64,
pub free_space: u64,
pub free_space_in_objects: u32,
pub description: Option<String>,
pub volume_identifier: String,
}
pub trait SessionStorageExt<D>
where
D: Device,
{
fn storages(
&mut self,
) -> impl Future<Output = Result<Vec<Storage>, MtpError<<D as PtpIo>::TransportError>>> + Send;
}
impl<D> SessionStorageExt<D> for MtpSession<D>
where
D: Device,
{
async fn storages(&mut self) -> Result<Vec<Storage>, MtpError<<D as PtpIo>::TransportError>> {
let storage_ids_response = self.get_storage_ids().await?;
let storage_ids = storage_ids_response.data.data;
let mut storages = Vec::with_capacity(storage_ids.len());
for storage_id in storage_ids.iter().copied() {
let storage_info_response = self.get_storage_info(storage_id).await?;
let storage_info = storage_info_response.data.data;
storages.push(Storage {
id: storage_id,
ty: storage_info.storage_type,
filesystem_type: storage_info.filesystem_type,
access_capability: storage_info.access_capability,
max_capacity: storage_info.max_capacity,
free_space: storage_info.free_space,
free_space_in_objects: storage_info.free_space_in_objects,
description: storage_info
.storage_description
.as_ref()
.map(ToString::to_string),
volume_identifier: storage_info.volume_identifier.to_string(),
});
}
Ok(storages)
}
}