pub struct StreamReader<T> { /* private fields */ }runtime and component-model and component-model-async only.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 is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns whether this stream is “closed” meaning that the other end of the stream has been dropped.
Sourcepub async fn read<B>(&mut self, accessor: impl AsAccessor, buffer: B) -> B
pub async fn read<B>(&mut self, accessor: impl AsAccessor, buffer: B) -> B
Read values from this stream.
The returned Future will yield a (Some(_), _) if the read completed
(possibly with zero items if the write was empty). It will return
(None, _) if the read failed due to the closure of the write end. In
either case, the returned buffer will be the same one passed as a
parameter, with zero or more items added.
§Panics
Panics if the store that the [Accessor] is derived from does not own
this future.
Sourcepub async fn watch_writer(&mut self, accessor: impl AsAccessor)
pub async fn watch_writer(&mut self, accessor: impl AsAccessor)
Wait until the write end of this stream is dropped.
§Panics
Panics if the store that the [Accessor] is derived from does not own
this future.
Sourcepub fn from_val(
store: impl AsContextMut<Data: Send>,
instance: Instance,
value: &Val,
) -> Result<Self>
pub fn from_val( store: impl AsContextMut<Data: Send>, instance: Instance, value: &Val, ) -> Result<Self>
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>) -> Self
fn from(guard: GuardedStreamReader<T, A>) -> Self
impl<T: Send + Sync> ComponentType for StreamReader<T>
impl<T: Send + Sync> Lift for StreamReader<T>
impl<T: Send + Sync> 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> UnsafeUnpin for StreamReader<T>
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
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