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
impl PythLazerClientBuilder
Sourcepub fn new(access_token: String) -> Self
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
Sourcepub fn with_endpoints(self, endpoints: Vec<Url>) -> Self
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.
Sourcepub fn with_num_connections(self, num_connections: usize) -> Self
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)
Sourcepub fn with_backoff(self, backoff: PythLazerExponentialBackoff) -> Self
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
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
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
Sourcepub fn with_channel_capacity(self, channel_capacity: usize) -> Self
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)
Sourcepub fn build(self) -> Result<PythLazerClient>
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§
impl Freeze for PythLazerClientBuilder
impl RefUnwindSafe for PythLazerClientBuilder
impl Send for PythLazerClientBuilder
impl Sync for PythLazerClientBuilder
impl Unpin for PythLazerClientBuilder
impl UnwindSafe for PythLazerClientBuilder
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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