Struct StreamAny
pub struct StreamAny { /* private fields */ }Expand description
Represents a type-erased component model stream.
This type is similar to ResourceAny
where it’s a static guarantee that it represents a component model
stream, but it does not contain any information about the underlying type
that is associated with this stream. This is intended to be used in
“dynamically typed” situations where embedders may not know ahead of time
the type of a stream being used by component that is loaded.
§Closing streams
A StreamAny represents a resource that is owned by a Store. Proper
disposal of a stream requires invoking the StreamAny::close method to
ensure that this handle does not leak. If StreamAny::close is not
called then memory will not be leaked once the owning Store is dropped,
but the resource handle will be leaked until the Store is dropped.
Note that special care should be taken when handling StreamAny in async
functions. In this scenario an async host function can be cancelled
(dropped) at any time and if a StreamAny it holds isn’t closed then the
stream will be leaked within the store until the store is dropped.
§Cloning
Cloning a StreamAny does not duplicate the underlying stream: all clones
refer to the same read end, whose ownership can only be transferred once.
After one clone has been lowered into a guest, piped, or closed, attempting
any of those with another clone returns an error.
Implementations§
§impl StreamAny
impl StreamAny
pub fn try_into_stream_reader<T>(self) -> Result<StreamReader<T>, Error>where
T: ComponentType + 'static,
pub fn try_into_stream_reader<T>(self) -> Result<StreamReader<T>, Error>where
T: ComponentType + 'static,
Attempts to convert this StreamAny to a StreamReader<T>
with a statically known type.
§Errors
This function will return an error if T does not match the type of
value on this stream.
pub fn try_from_stream_reader<T>(
store: impl AsContextMut,
reader: StreamReader<T>,
) -> Result<StreamAny, Error>where
T: ComponentType + 'static,
pub fn try_from_stream_reader<T>(
store: impl AsContextMut,
reader: StreamReader<T>,
) -> Result<StreamAny, Error>where
T: ComponentType + 'static,
pub fn close(&mut self, store: impl AsContextMut) -> Result<(), Error>
pub fn close(&mut self, store: impl AsContextMut) -> Result<(), Error>
Close this StreamAny.
This will close this stream and cause any write that happens later to
returned DROPPED.
§Errors
Returns an error if this stream has already been closed or otherwise
transferred (e.g. lowered into a guest), or if it does not belong to
store.
Trait Implementations§
impl ComponentType for StreamAny
impl Lift for StreamAny
impl Lower for StreamAny
impl StructuralPartialEq for StreamAny
Auto Trait Implementations§
impl Freeze for StreamAny
impl RefUnwindSafe for StreamAny
impl Send for StreamAny
impl Sync for StreamAny
impl Unpin for StreamAny
impl UnsafeUnpin for StreamAny
impl UnwindSafe for StreamAny
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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