PythLazerClientBuilder

Struct PythLazerClientBuilder 

Source
pub struct PythLazerClientBuilder { /* private fields */ }
Expand description

A builder for creating PythLazerClient instances with customizable configuration.

The builder provides a convenient way to configure a Pyth Lazer client with sensible defaults while allowing customization of all parameters. It follows the builder pattern for a fluent API.

§Default Configuration

  • Endpoints: Uses Pyth Lazer’s default production endpoints
  • Connections: 4 concurrent WebSocket connections
  • Timeout: 5 seconds for WebSocket operations
  • Backoff: Exponential backoff with default settings
  • Channel Capacity: Uses the default 1000

Implementations§

Source§

impl PythLazerClientBuilder

Source

pub fn new(access_token: String) -> Self

Creates a new builder with default configuration.

This initializes the builder with sensible defaults for production use:

  • Default Pyth Lazer endpoints
  • 4 WebSocket connections
  • 5-second timeout
§Arguments
  • access_token - The authentication token for accessing Pyth Lazer services
Source

pub fn with_endpoints(self, endpoints: Vec<Url>) -> Self

Sets custom WebSocket endpoints for the client.

By default, the client uses Pyth Lazer’s production endpoints. Use this method to connect to different environments (staging, local development) or to use custom endpoint configurations.

§Arguments
  • endpoints - A vector of WebSocket endpoint URLs. Must not be empty.
Source

pub fn with_num_connections(self, num_connections: usize) -> Self

Sets the number of concurrent WebSocket connections to maintain.

More connections provide better redundancy and can improve throughput, but also consume more resources.

§Arguments
  • num_connections - The number of WebSocket connections (must be > 0)
Source

pub fn with_backoff(self, backoff: PythLazerExponentialBackoff) -> Self

Sets the exponential backoff configuration for connection retries.

The backoff strategy determines how the client handles connection failures and retries.

§Arguments
  • backoff - The exponential backoff configuration
Source

pub fn with_timeout(self, timeout: Duration) -> Self

Sets the timeout duration for WebSocket operations.

This timeout applies to each WebSocket connection, if no response is received within this duration, the connection will be considered failed and retried.

§Arguments
  • timeout - The timeout duration for each WebSocket
Source

pub fn with_channel_capacity(self, channel_capacity: usize) -> Self

Sets the capacity of the internal message channel.

This determines how many messages can be buffered internally before the client starts applying backpressure.

§Arguments
  • channel_capacity - The channel capacity (number of messages)
Source

pub fn build(self) -> Result<PythLazerClient>

Builds the configured PythLazerClient instance.

This consumes the builder and creates a new client with the specified configuration. The client is ready to use but connections are not established until PythLazerClient::start is called.

§Returns

Returns Ok(PythLazerClient) on success, or an error if the configuration is invalid.

§Errors

Returns an error if:

  • No endpoints are configured
  • Any configuration parameter is invalid

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