pub struct BoxedStream<T, E> { /* private fields */ }Expand description
A boxed stream type that can be used with the websocket protocol.
You can easily convert any static type that implement futures::Stream into a BoxedStream
with the From trait.
§Example
use futures::StreamExt;
use server_fn::{BoxedStream, ServerFnError};
let stream: BoxedStream<_, ServerFnError> =
futures::stream::iter(0..10).map(Result::Ok).into();Methods from Deref<Target = Pin<Box<dyn Stream<Item = Result<T, E>> + Send>>>§
1.33.0 · Sourcepub fn as_ref(&self) -> Pin<&<Ptr as Deref>::Target>where
Ptr: Deref,
pub fn as_ref(&self) -> Pin<&<Ptr as Deref>::Target>where
Ptr: Deref,
Gets a shared reference to the pinned value this Pin points to.
This is a generic method to go from &Pin<Pointer<T>> to Pin<&T>.
It is safe because, as part of the contract of Pin::new_unchecked,
the pointee cannot move after Pin<Pointer<T>> got created.
“Malicious” implementations of Pointer::Deref are likewise
ruled out by the contract of Pin::new_unchecked.
1.33.0 · Sourcepub fn as_mut(&mut self) -> Pin<&mut <Ptr as Deref>::Target>where
Ptr: DerefMut,
pub fn as_mut(&mut self) -> Pin<&mut <Ptr as Deref>::Target>where
Ptr: DerefMut,
Gets a mutable reference to the pinned value this Pin<Ptr> points to.
This is a generic method to go from &mut Pin<Pointer<T>> to Pin<&mut T>.
It is safe because, as part of the contract of Pin::new_unchecked,
the pointee cannot move after Pin<Pointer<T>> got created.
“Malicious” implementations of Pointer::DerefMut are likewise
ruled out by the contract of Pin::new_unchecked.
This method is useful when doing multiple calls to functions that consume the pinning pointer.
§Example
use std::pin::Pin;
impl Type {
fn method(self: Pin<&mut Self>) {
// do something
}
fn call_method_twice(mut self: Pin<&mut Self>) {
// `method` consumes `self`, so reborrow the `Pin<&mut Self>` via `as_mut`.
self.as_mut().method();
self.as_mut().method();
}
}1.84.0 · Sourcepub fn as_deref_mut(
self: Pin<&mut Pin<Ptr>>,
) -> Pin<&mut <Ptr as Deref>::Target>where
Ptr: DerefMut,
pub fn as_deref_mut(
self: Pin<&mut Pin<Ptr>>,
) -> Pin<&mut <Ptr as Deref>::Target>where
Ptr: DerefMut,
Gets Pin<&mut T> to the underlying pinned value from this nested Pin-pointer.
This is a generic method to go from Pin<&mut Pin<Pointer<T>>> to Pin<&mut T>. It is
safe because the existence of a Pin<Pointer<T>> ensures that the pointee, T, cannot
move in the future, and this method does not enable the pointee to move. “Malicious”
implementations of Ptr::DerefMut are likewise ruled out by the contract of
Pin::new_unchecked.
1.33.0 · Sourcepub fn set(&mut self, value: <Ptr as Deref>::Target)
pub fn set(&mut self, value: <Ptr as Deref>::Target)
Assigns a new value to the memory location pointed to by the Pin<Ptr>.
This overwrites pinned data, but that is okay: the original pinned value’s destructor gets
run before being overwritten and the new value is also a valid value of the same type, so
no pinning invariant is violated. See the pin module documentation
for more information on how this upholds the pinning invariants.
§Example
use std::pin::Pin;
let mut val: u8 = 5;
let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
println!("{}", pinned); // 5
pinned.set(10);
println!("{}", pinned); // 10Trait Implementations§
Source§impl<T, E> Debug for BoxedStream<T, E>
impl<T, E> Debug for BoxedStream<T, E>
Source§impl<T, E> Deref for BoxedStream<T, E>
impl<T, E> Deref for BoxedStream<T, E>
Source§impl<T, E> DerefMut for BoxedStream<T, E>
impl<T, E> DerefMut for BoxedStream<T, E>
Source§impl<T, E, S> From<S> for BoxedStream<T, E>
impl<T, E, S> From<S> for BoxedStream<T, E>
Source§fn from(stream: S) -> BoxedStream<T, E>
fn from(stream: S) -> BoxedStream<T, E>
Source§impl<Input, InputItem, OutputItem, InputEncoding, OutputEncoding, Client, Server, Error, InputStreamError, OutputStreamError> Protocol<Input, BoxedStream<OutputItem, OutputStreamError>, Client, Server, Error, InputStreamError, OutputStreamError> for Websocket<InputEncoding, OutputEncoding>where
Input: Deref<Target = BoxedStream<InputItem, InputStreamError>> + Into<BoxedStream<InputItem, InputStreamError>> + From<BoxedStream<InputItem, InputStreamError>>,
InputEncoding: Encodes<InputItem> + Decodes<InputItem>,
OutputEncoding: Encodes<OutputItem> + Decodes<OutputItem>,
InputStreamError: FromServerFnError + Send,
OutputStreamError: FromServerFnError + Send,
Error: FromServerFnError + Send,
Server: Server<Error, InputStreamError, OutputStreamError>,
Client: Client<Error, InputStreamError, OutputStreamError>,
OutputItem: Send + 'static,
InputItem: Send + 'static,
impl<Input, InputItem, OutputItem, InputEncoding, OutputEncoding, Client, Server, Error, InputStreamError, OutputStreamError> Protocol<Input, BoxedStream<OutputItem, OutputStreamError>, Client, Server, Error, InputStreamError, OutputStreamError> for Websocket<InputEncoding, OutputEncoding>where
Input: Deref<Target = BoxedStream<InputItem, InputStreamError>> + Into<BoxedStream<InputItem, InputStreamError>> + From<BoxedStream<InputItem, InputStreamError>>,
InputEncoding: Encodes<InputItem> + Decodes<InputItem>,
OutputEncoding: Encodes<OutputItem> + Decodes<OutputItem>,
InputStreamError: FromServerFnError + Send,
OutputStreamError: FromServerFnError + Send,
Error: FromServerFnError + Send,
Server: Server<Error, InputStreamError, OutputStreamError>,
Client: Client<Error, InputStreamError, OutputStreamError>,
OutputItem: Send + 'static,
InputItem: Send + 'static,
Source§async fn run_server<F, Fut>(
request: <Server as Server<Error, InputStreamError, OutputStreamError>>::Request,
server_fn: F,
) -> Result<<Server as Server<Error, InputStreamError, OutputStreamError>>::Response, Error>
async fn run_server<F, Fut>( request: <Server as Server<Error, InputStreamError, OutputStreamError>>::Request, server_fn: F, ) -> Result<<Server as Server<Error, InputStreamError, OutputStreamError>>::Response, Error>
Source§fn run_client(
path: &str,
input: Input,
) -> impl Future<Output = Result<BoxedStream<OutputItem, OutputStreamError>, Error>> + Send
fn run_client( path: &str, input: Input, ) -> impl Future<Output = Result<BoxedStream<OutputItem, OutputStreamError>, Error>> + Send
Auto Trait Implementations§
impl<T, E> Freeze for BoxedStream<T, E>
impl<T, E> !RefUnwindSafe for BoxedStream<T, E>
impl<T, E> Send for BoxedStream<T, E>
impl<T, E> !Sync for BoxedStream<T, E>
impl<T, E> Unpin for BoxedStream<T, E>
impl<T, E> !UnwindSafe for BoxedStream<T, E>
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