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 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.
pub 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.
pub 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.
pub fn from_val(
store: impl AsContextMut,
instance: Instance,
value: &Val,
) -> Result<StreamReader<T>, Error>
pub fn from_val( store: impl AsContextMut, instance: Instance, value: &Val, ) -> Result<StreamReader<T>, Error>
Attempt to convert the specified Val
to a StreamReader
.
pub 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.
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.
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>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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