Skip to main content

SteamClientBuilder

Struct SteamClientBuilder 

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

Builder for creating SteamClient instances with customized dependencies.

Use this builder when you need to inject mock implementations for testing or customize the behavior of the Steam client.

§Testing Example

use steam_client::{SteamClient, SteamClientBuilder};

// Create a test client with mocked dependencies
let (client, mocks) = SteamClient::builder().with_mock_http().build_with_mocks();

assert!(!client.is_logged_in());

§Production Example

use steam_client::{SteamClient, SteamOptions};

// For production, just use SteamClient::new()
let client = SteamClient::new(SteamOptions::default());

Implementations§

Source§

impl SteamClientBuilder

Source

pub fn new() -> Self

Create a new builder with default settings.

The default configuration uses:

  • SteamOptions::default()
  • HttpCmServerProvider::new_default()
  • ReqwestHttpClient (lazy initialized in build)
  • SystemClock (lazy initialized in build)
  • ThreadRng (lazy initialized in build)
Source

pub fn with_options(self, options: SteamOptions) -> Self

Set the options for the Steam client.

These options control high-level behavior like auto-relogin, proxy settings, and connection protocols.

If not called, the client will be built using SteamOptions::default().

Source

pub fn with_http_client(self, client: Arc<dyn HttpClient>) -> Self

Use a custom HTTP client.

This is useful for providing a custom-configured reqwest client or a completely different implementation of the HttpClient trait.

Source

pub fn with_mock_http(self) -> Self

Use a mock HTTP client for testing.

Returns a client that records requests and returns queued responses. Use build_with_mocks() to get access to the mock for test assertions.

Source

pub fn with_mock_http_responses(self, responses: Vec<HttpResponse>) -> Self

Use a mock HTTP client with pre-queued responses.

This is a convenience method for short tests that only need to verify sequence of HTTP responses.

Source

pub fn with_clock(self, clock: Arc<dyn Clock>) -> Self

Use a custom clock.

The clock is used for timing heartbeats, measuring timeouts, and other time-sensitive logic.

Source

pub fn with_mock_clock(self) -> Self

Use a mock clock for testing.

The mock clock starts at time zero and can be advanced manually. Use build_with_mocks() to get access to the mock for time control.

Source

pub fn with_rng(self, rng: Arc<dyn Rng>) -> Self

Use a custom random number generator.

The RNG is used for generating session IDs, encryption keys, and other randomized values.

Source

pub fn with_mock_rng(self) -> Self

Use a mock RNG for testing.

The mock RNG returns deterministic values that can be set. Use build_with_mocks() to get access to the mock for value control.

Source

pub fn with_mock_rng_values( self, usize_val: usize, i32_val: i32, u32_val: u32, ) -> Self

Use a mock RNG with specific initial values.

Provides deterministic values for usize, i32, and u32 requests.

Source

pub fn with_all_mocks(self) -> Self

Configure all other dependencies with mock implementations.

Equivalent to calling with_mock_http(), with_mock_clock(), and with_mock_rng().

Source

pub fn build(self) -> SteamClient

Build the SteamClient instance.

Source

pub fn build_with_mocks(self) -> (SteamClient, MockHandles)

Build the SteamClient and return handles to any mock dependencies.

This is useful in tests where you need to control mock behavior or inspect recorded interactions.

§Example
use std::time::Duration;

use steam_client::{utils::http::HttpResponse, SteamClient};

let (client, mocks) = SteamClient::builder()
    .with_mock_http()
    .with_mock_clock()
    .build_with_mocks();

// Control the mock clock
if let Some(clock) = &mocks.clock {
    clock.advance(Duration::from_secs(10));
}

// Inspect HTTP requests
if let Some(http) = &mocks.http {
    assert_eq!(http.request_count(), 0);
}

Trait Implementations§

Source§

impl Default for SteamClientBuilder

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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