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
impl SteamClientBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with default settings.
The default configuration uses:
SteamOptions::default()HttpCmServerProvider::new_default()ReqwestHttpClient(lazy initialized inbuild)SystemClock(lazy initialized inbuild)ThreadRng(lazy initialized inbuild)
Sourcepub fn with_options(self, options: SteamOptions) -> Self
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().
Sourcepub fn with_http_client(self, client: Arc<dyn HttpClient>) -> Self
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.
Sourcepub fn with_mock_http(self) -> Self
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.
Sourcepub fn with_mock_http_responses(self, responses: Vec<HttpResponse>) -> Self
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.
Sourcepub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
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.
Sourcepub fn with_mock_clock(self) -> Self
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.
Sourcepub fn with_rng(self, rng: Arc<dyn Rng>) -> Self
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.
Sourcepub fn with_mock_rng(self) -> Self
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.
Sourcepub fn with_mock_rng_values(
self,
usize_val: usize,
i32_val: i32,
u32_val: u32,
) -> Self
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.
Sourcepub fn with_all_mocks(self) -> Self
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().
Sourcepub fn build(self) -> SteamClient
pub fn build(self) -> SteamClient
Build the SteamClient instance.
- Clock:
SystemClock - RNG:
ThreadRng - CM Provider: [
HttpCmServerProvider]
Sourcepub fn build_with_mocks(self) -> (SteamClient, MockHandles)
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§
Auto Trait Implementations§
impl Freeze for SteamClientBuilder
impl !RefUnwindSafe for SteamClientBuilder
impl Send for SteamClientBuilder
impl Sync for SteamClientBuilder
impl Unpin for SteamClientBuilder
impl UnsafeUnpin for SteamClientBuilder
impl !UnwindSafe for SteamClientBuilder
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