Skip to main content

BoxedStream

Struct BoxedStream 

Source
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 · Source

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 · Source

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 · Source

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 · Source

pub fn set(&mut self, value: <Ptr as Deref>::Target)
where <Ptr as Deref>::Target: Sized,

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); // 10

Trait Implementations§

Source§

impl<T, E> Debug for BoxedStream<T, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T, E> Deref for BoxedStream<T, E>

Source§

type Target = Pin<Box<dyn Stream<Item = Result<T, E>> + Send>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<BoxedStream<T, E> as Deref>::Target

Dereferences the value.
Source§

impl<T, E> DerefMut for BoxedStream<T, E>

Source§

fn deref_mut(&mut self) -> &mut <BoxedStream<T, E> as Deref>::Target

Mutably dereferences the value.
Source§

impl<T, E> From<BoxedStream<T, E>> for Pin<Box<dyn Stream<Item = Result<T, E>> + Send>>

Source§

fn from( val: BoxedStream<T, E>, ) -> Pin<Box<dyn Stream<Item = Result<T, E>> + Send>>

Converts to this type from the input type.
Source§

impl<T, E, S> From<S> for BoxedStream<T, E>
where S: Stream<Item = Result<T, E>> + Send + 'static,

Source§

fn from(stream: S) -> BoxedStream<T, E>

Converts to this type from the input type.
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,

Source§

const METHOD: Method = Method::GET

The HTTP method used for requests.
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>
where F: Fn(Input) -> Fut + Send, Fut: Future<Output = Result<BoxedStream<OutputItem, OutputStreamError>, Error>> + Send,

Run the server function on the server. The implementation should handle deserializing the input, running the server function, and serializing the output.
Source§

fn run_client( path: &str, input: Input, ) -> impl Future<Output = Result<BoxedStream<OutputItem, OutputStreamError>, Error>> + Send

Run the server function on the client. The implementation should handle serializing the input, sending the request, and deserializing the output.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> SerializableKey for T

Source§

fn ser_key(&self) -> String

Serializes the key to a unique string. Read more
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.