pub struct StreamReader<T> { /* private fields */ }
Expand description
Represents the readable end of a Component Model stream
.
Note that StreamReader
instances must be disposed of using close
;
otherwise the in-store representation will leak and the writer end will hang
indefinitely. Consider using GuardedStreamReader
to ensure that
disposal happens automatically.
Implementations§
Source§impl<T> StreamReader<T>
impl<T> StreamReader<T>
Sourcepub fn new<S>(
store: S,
producer: impl StreamProducer<<S as AsContext>::Data, Item = T>,
) -> StreamReader<T>
pub fn new<S>( store: S, producer: impl StreamProducer<<S as AsContext>::Data, Item = T>, ) -> StreamReader<T>
Create a new stream with the specified producer.
Sourcepub fn try_into<V>(self, store: impl AsContextMut) -> Result<V, StreamReader<T>>where
V: 'static,
pub fn try_into<V>(self, store: impl AsContextMut) -> Result<V, StreamReader<T>>where
V: 'static,
Attempt to consume this object by converting it into the specified type.
This can be useful for “short-circuiting” host-to-host streams, bypassing the guest entirely. For example, if a guest task returns a host-created stream and then exits, this function may be used to retrieve the write end, after which the guest instance and store may be disposed of if no longer needed.
This will return Ok(_)
if and only if the following conditions are
met:
-
The stream was created by the host (i.e. not by the guest).
-
The
StreamProducer::try_into
function returnsOk(_)
when given the producer provided toStreamReader::new
when the stream was created, along withTypeId::of::<V>()
.
Sourcepub fn pipe<S>(
self,
store: S,
consumer: impl StreamConsumer<<S as AsContext>::Data, Item = T>,
)where
S: AsContextMut,
T: 'static,
pub fn pipe<S>(
self,
store: S,
consumer: impl StreamConsumer<<S as AsContext>::Data, Item = T>,
)where
S: AsContextMut,
T: 'static,
Set the consumer that accepts the items delivered to this stream.
Sourcepub fn from_val(
store: impl AsContextMut,
value: &Val,
) -> Result<StreamReader<T>, Error>
pub fn from_val( store: impl AsContextMut, value: &Val, ) -> Result<StreamReader<T>, Error>
Attempt to convert the specified Val
to a StreamReader
.
Sourcepub fn close(&mut self, store: impl AsContextMut)
pub fn close(&mut self, store: impl AsContextMut)
Close this StreamReader
, writing the default value.
§Panics
Panics if the store that the [Accessor
] is derived from does not own
this future. Usage of this future after calling close
will also cause
a panic.
Sourcepub fn close_with(&mut self, accessor: impl AsAccessor)
pub fn close_with(&mut self, accessor: impl AsAccessor)
Convenience method around Self::close
.
Sourcepub fn guard<A>(self, accessor: A) -> GuardedStreamReader<T, A>where
A: AsAccessor,
pub fn guard<A>(self, accessor: A) -> GuardedStreamReader<T, A>where
A: AsAccessor,
Returns a GuardedStreamReader
which will auto-close this stream on
drop and clean it up from the store.
Note that the accessor
provided must own this future and is
additionally transferred to the GuardedStreamReader
return value.
Trait Implementations§
Source§impl<T> Debug for StreamReader<T>
impl<T> Debug for StreamReader<T>
Source§impl<T, A> From<GuardedStreamReader<T, A>> for StreamReader<T>where
A: AsAccessor,
impl<T, A> From<GuardedStreamReader<T, A>> for StreamReader<T>where
A: AsAccessor,
Source§fn from(guard: GuardedStreamReader<T, A>) -> StreamReader<T>
fn from(guard: GuardedStreamReader<T, A>) -> StreamReader<T>
impl<T> ComponentType for StreamReader<T>
impl<T> Lift for StreamReader<T>
impl<T> Lower for StreamReader<T>
Auto Trait Implementations§
impl<T> Freeze for StreamReader<T>
impl<T> RefUnwindSafe for StreamReader<T>where
T: RefUnwindSafe,
impl<T> Send for StreamReader<T>where
T: Send,
impl<T> Sync for StreamReader<T>where
T: Sync,
impl<T> Unpin for StreamReader<T>where
T: Unpin,
impl<T> UnwindSafe for StreamReader<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more