InvocationBuilder

Struct InvocationBuilder 

Source
pub struct InvocationBuilder<'a> { /* private fields */ }
Expand description

Request builder for the SignalRClient

Allows adding streams and arguments to the invocation. Contains set of method that drive behavior of response reception.

Implementations§

Source§

impl<'a> InvocationBuilder<'a>

Source

pub fn arg<A, B>(self, arg: A) -> Result<Self, ClientError>
where A: Into<InvocationArgs<B>> + Send + 'static, B: Serialize + Send + 'static,

Adds ordered argument to invocation

Argument can either be:

Order of arguments matters, they need to be passed in exactly the same order server expects them.

§Example

Assuming server has a hub method defined as:

use futures::stream::Stream;

fn calculate(name: String, a: usize, b: usize, items: impl Stream<Item = usize>) -> usize {
    println!("{}", name);
    a + b
}

Innvocation would have to be built in a following way to call this method

use signalrs_client::{SignalRClient, arguments::InvocationStream};
use futures::StreamExt;

let client: SignalRClient = get_client();
let result = client.method("calculate")
    .arg("Johnny")?
    .arg(1)?
    .arg(2)?
    .arg(InvocationStream::new(futures::stream::repeat(1usize).take(5)))?   
    .invoke::<usize>()
    .await?;
Source

pub async fn send(self) -> Result<(), ClientError>

Sends an invocation to the server and does not expect any response

This method follows ‘fire and forget’ semantics. As soon as the message is sent from the client it returns to the caller. Server then processes the request asynchronously.

Source

pub async fn invoke_unit(self) -> Result<(), ClientError>

Sends an ivocation to the server and awaits unit response

It does not expect any meaingful reponse except from empty response from the server. It follows semantics such as void methods or functions returning ().

Source

pub async fn invoke<T: DeserializeOwned>(self) -> Result<T, ClientError>

Sends an ivocation to the server and awaits meaningful, single response

It expects the response to be well-structured object in an encoding format used for communication. For instance this method can return usize or MyCustomStruct as long as this type implements Deserialize and is not generic over lifetime.

§Important

This function will cause errors if called with (). Use invoke_unit to do this.

Source

pub async fn invoke_stream<T: DeserializeOwned>( self, ) -> Result<ResponseStream<'a, T>, ClientError>

Sends an ivocation to the server and awaits meaningful stream of responses

It expects the responses to be well-structured objects in an encoding format used for communication. For instance this method can return a Stream of usize or MyCustomStruct as long as this type implements Deserialize and is not generic over lifetime.

§Example

Assuming server has a hub method defined as:

use futures::stream::Stream;
use futures::stream::StreamExt;
fn answers() -> impl Stream<Item = String> {
    // not really important what happens here
}

Innvocation would have to be built in a following way to call this method

use signalrs_client::{SignalRClient, arguments::InvocationStream};
use futures::StreamExt;

let client: SignalRClient = get_client();
let mut result = client.method("answers")
    .invoke_stream::<String>().await?;

while let Some(answer) = result.next().await {
    println!("next answer: {}", answer?);
}

Auto Trait Implementations§

§

impl<'a> Freeze for InvocationBuilder<'a>

§

impl<'a> !RefUnwindSafe for InvocationBuilder<'a>

§

impl<'a> Send for InvocationBuilder<'a>

§

impl<'a> !Sync for InvocationBuilder<'a>

§

impl<'a> Unpin for InvocationBuilder<'a>

§

impl<'a> !UnwindSafe for InvocationBuilder<'a>

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<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,