pub struct ObjectListing { /* private fields */ }Expand description
An in-progress directory listing that yields ObjectInfo items one at a time.
Created by Storage::list_objects_stream(). After GetObjectHandles completes,
the total count is known immediately. Each call to next() fetches
one GetObjectInfo from USB, so the consumer can report progress (e.g.,
“Loading files (42 of 500)…”) as items arrive.
§Important
The MTP session is busy while this listing is active. You must consume all items (or drop the listing) before calling other storage methods.
§Example
use mtp_rs::mtp::MtpDevice;
let mut listing = storage.list_objects_stream(None).await?;
println!("Loading {} files...", listing.total());
while let Some(result) = listing.next().await {
let info = result?;
println!("[{}/{}] {}", listing.fetched(), listing.total(), info.filename);
}Implementations§
Source§impl ObjectListing
impl ObjectListing
Sourcepub fn total(&self) -> usize
pub fn total(&self) -> usize
Total number of object handles returned by the device.
When a parent filter is active (e.g., Fuji devices that return all objects for root), some items may be skipped, so the actual yielded count can be lower.
Sourcepub fn fetched(&self) -> usize
pub fn fetched(&self) -> usize
Number of handles processed so far (including filtered-out items).
Sourcepub async fn next(&mut self) -> Option<Result<ObjectInfo, Error>>
pub async fn next(&mut self) -> Option<Result<ObjectInfo, Error>>
Fetch the next object from the device.
Returns None when all handles have been processed.
Items that don’t match the parent filter are silently skipped.
If a CancelToken was passed via
Storage::list_objects_stream_with_cancel and it’s been cancelled,
this returns Some(Err(Error::Cancelled)) at the next per-handle
boundary (typically within one GetObjectInfo USB roundtrip).