Skip to main content

ObjectListing

Struct ObjectListing 

Source
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 the device returns the handle list, the total count is known immediately (total()). Each call to next() fetches one object’s metadata, so the consumer can report progress (e.g., “Loading files (42 of 500)…”) as items arrive.

§Important

The device 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::{ListingItem, MtpDevice};

let mut listing = storage.list_objects_stream(None).await?;
println!("Loading {} files...", listing.total());

while let Some(item) = listing.next().await {
    match item? {
        ListingItem::Object(info) => {
            println!("[{}/{}] {}", listing.fetched(), listing.total(), info.filename);
        }
        ListingItem::Skipped(skipped) => {
            eprintln!("could not read handle {}: {}", skipped.handle.0, skipped.error);
        }
    }
}

Implementations§

Source§

impl ObjectListing

Source

pub fn total(&self) -> usize

Total number of object handles returned by the device.

When a parent filter is active (e.g. devices that return all objects for root), some items may be skipped, so the actual yielded count can be lower.

Source

pub fn fetched(&self) -> usize

Number of items yielded so far.

Source

pub async fn next(&mut self) -> Option<Result<ListingItem, Error>>

Fetch the next item from the device.

Returns None when the listing is exhausted. Items that don’t match the parent filter are skipped by the backend and never surface here.

The Ok side has two shapes, and the distinction is the whole point: a ListingItem::Object is an object whose metadata was read, and a ListingItem::Skipped is one handle the device refused in a way that leaves the rest of the listing usable (see Storage::collect_objects for what qualifies). An Err means the listing itself is over: transport trouble, a broken session, cancellation, a malformed response.

So Err is “stop”, Ok(Skipped) is “this one is unreadable, keep going”, and you can’t confuse them by accident. Consumers that don’t care can filter:

let mut listing = storage.list_objects_stream(None).await?;
while let Some(item) = listing.next().await {
    if let ListingItem::Object(info) = item? {
        println!("{}", info.filename);
    }
}

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.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more