Struct StreamReader
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§
§impl<T> StreamReader<T>
impl<T> StreamReader<T>
pub 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.
pub 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_intofunction returnsOk(_)when given the producer provided toStreamReader::newwhen the stream was created, along withTypeId::of::<V>().
pub 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.
pub fn close(&mut self, store: impl AsContextMut)
pub fn close(&mut self, store: impl AsContextMut)
Close this StreamReader.
This will signal that this portion of the stream is closed causing all future writes to return immediately with “DROPPED”.
§Panics
Panics if the store does not own this future. Usage of this future
after calling close will also cause a panic.
pub fn close_with(&mut self, accessor: impl AsAccessor)
pub fn close_with(&mut self, accessor: impl AsAccessor)
Convenience method around Self::close.
pub 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.
pub fn try_into_stream_any(
self,
store: impl AsContextMut,
) -> Result<StreamAny, Error>where
T: ComponentType + 'static,
pub fn try_into_stream_any(
self,
store: impl AsContextMut,
) -> Result<StreamAny, Error>where
T: ComponentType + 'static,
Attempts to convert this StreamReader<T> to a StreamAny.
§Errors
This function will return an error if self does not belong to
store.
pub fn try_from_stream_any(stream: StreamAny) -> Result<StreamReader<T>, Error>where
T: ComponentType + 'static,
pub fn try_from_stream_any(stream: StreamAny) -> Result<StreamReader<T>, Error>where
T: ComponentType + 'static,
Attempts to convert a StreamAny into a StreamReader<T>.
§Errors
This function will fail if T doesn’t match the type of the value that
stream is sending.
Trait Implementations§
§impl<T> Debug for StreamReader<T>
impl<T> Debug for StreamReader<T>
§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,
§fn from(guard: GuardedStreamReader<T, A>) -> StreamReader<T>
fn from(guard: GuardedStreamReader<T, A>) -> StreamReader<T>
impl<T> ComponentType for StreamReader<T>where
T: ComponentType,
impl<T> Lift for StreamReader<T>where
T: ComponentType,
impl<T> Lower for StreamReader<T>where
T: ComponentType,
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