Struct vtubestudio::client::ClientBuilder

source ·
pub struct ClientBuilder { /* private fields */ }
Expand description

A builder to configure a new Client with a set of recommended tower middleware.

§Example

use vtubestudio::{Client, ClientEvent};

// An auth token from a previous successful authentication request
let stored_token = Some("...".to_string());

let (mut client, mut events) = Client::builder()
    .authentication("Plugin name", "Developer name", None)
    .auth_token(stored_token)
    .build_tungstenite();

tokio::spawn(async move {
    while let Some(event) = events.next().await {
        match event {
            ClientEvent::NewAuthToken(token) =>
               println!("Got new token: {token}"),
            _ =>
               println!("Received event {:?}", event),
        }
    }
});

Implementations§

source§

impl ClientBuilder

source

pub fn new() -> Self

Creates new builder with default values.

source

pub fn build_tungstenite(self) -> (Client, ClientEventStream)

Available on crate feature tokio-tungstenite only.

Consumes the builder and initializes a Client and ClientEventStream using tokio_tungstenite as the underlying websocket transport library.

source

pub fn authentication<S1, S2, S3>( self, name: S1, developer: S2, icon: S3, ) -> Self
where S1: Into<Cow<'static, str>>, S2: Into<Cow<'static, str>>, S3: Into<Option<Cow<'static, str>>>,

If this is provided, whenever the underlying service encounters an authentication error, it will try to obtain a new auth token and retry the request.

source

pub fn url<S: Into<String>>(self, url: S) -> Self

Sets the websocket URL. The default value is ws://localhost:8001.

source

pub fn auth_token(self, token: Option<String>) -> Self

Initial token to use for reauthentication (if authentication is provided). This should be the result of a previous successful authentication attempt.

source

pub fn retry_on_disconnect(self, retry: bool) -> Self

Retry requests on disconnect. The default value is true.

source

pub fn request_buffer_size(self, size: usize) -> Self

The max number of outstanding requests/responses.

The default value is 128.

source

pub fn event_buffer_size(self, size: usize) -> Self

The max capacity of the ClientEventStream buffer.

This represents the max number of unacknowledged new events before the client stops sending them.

The default value is 128.

source

pub fn build_service<S>(self, service: S) -> (Client, ClientEventStream)
where S: Service<RequestEnvelope, Response = ResponseEnvelope> + Send + 'static, S::Error: Into<BoxError> + Send + Sync, S::Future: Send,

Consumes the builder and initializes a Client and ClientEventStream using a custom Service.

Note the ClientEventStream will only yield ClientEvent::NewAuthToken events. To receive all events, use ClientBuilder::build_connector.

source

pub fn build_connector<M>(self, connector: M) -> (Client, ClientEventStream)
where M: MakeTransport<String, RequestEnvelope, Item = ResponseEnvelope> + Send + Clone + 'static, M::Future: Send + 'static, M::Transport: Send + 'static, M::MakeError: StdError + Send + Sync + 'static, M::Error: Send, BoxError: From<M::Error> + From<M::SinkError>,

Consumes the builder and initializes a Client and ClientEventStream with a connector.

The input connector should be a MakeTransport that meets the requirements of Reconnect.

source

pub fn build_reconnecting_service<S>( self, maker: S, ) -> (Client, ClientEventStream)

Consumes the builder and initializes a Client and ClientEventStream with a reconnecting service.

The input service should be a MakeService that satisfies the requirements of Reconnect.

Note the ClientEventStream will only yield ClientEvent::NewAuthToken events. To receive all events, use ClientBuilder::build_connector.

Trait Implementations§

source§

impl Clone for ClientBuilder

source§

fn clone(&self) -> ClientBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ClientBuilder

source§

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

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

impl Default for ClientBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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