Trait vfs::directory::dirents_sink::Sealed

source ·
pub trait Sealed: Send {
    // Required method
    fn open(self: Box<Self>) -> Box<dyn Any>;
}
Expand description

When a sink has reached it’s full capacity or when the producer has exhausted all the values it had, sink is transformed into a value that implements this trait. It helps to reduce the number of possible states the sink has. Once “sealed” it can not be converted back into a Sink instance. And the only way forward is to call the Self::open() method to downcast sink into the underlying type that gives access to the data that the sink have stored.

Required Methods§

source

fn open(self: Box<Self>) -> Box<dyn Any>

Converts a “sealed” sink into Any that can be later cast into a specific type that the consumer of the full sink can use to extract contained data.

TODO It would be awesome to have a method that converts Sealed into a specific underlying type directly. With the underlying type somehow only known by the code that constructed the Sink in the first place. And not to the code that is operating on the Sink/Sealed values via the trait. But I could not find a way to express that.

Seems like an associated type would express that, but if I add an associated type to both Sink and Sealed, I need any method that consumes the sink to be generic over this type. And that means that sink consumers are not object safe :( I think generic methods might be object safe, as long as they do not use their type arguments, which seems pointless, but here would be used to make sure that the type of the returned object is preserved. Maybe ?Sized would be a good boundary for generic methods allowed in traits?

Implementors§