Skip to main content

steam_user/
fallback.rs

1#[cfg(feature = "gas")]
2use crate::gas::GasSteamUser;
3#[cfg(feature = "remote")]
4use crate::remote::RemoteSteamUser;
5use crate::{
6    action::{ActionContext, ApiAction},
7    client::SteamUser,
8    error::SteamUserError,
9    steam_user_api::SteamUserApi,
10};
11
12/// A composite client that attempts requests across local, remote, and GAS
13/// clients sequentially.
14///
15/// Note: To keep things simple and unified across error types, the
16/// `SteamUserApi` implementation for `FallbackSteamUser` returns
17/// `SteamUserError`. If `remote` or `gas` fail, their errors are mapped to a
18/// `SteamUserError::Other`.
19pub struct FallbackSteamUser {
20    pub local: SteamUser,
21    #[cfg(feature = "remote")]
22    pub remote: Option<RemoteSteamUser>,
23    #[cfg(feature = "gas")]
24    pub gas: Option<GasSteamUser>,
25}
26
27impl FallbackSteamUser {
28    pub fn new(local: SteamUser) -> Self {
29        Self {
30            local,
31            #[cfg(feature = "remote")]
32            remote: None,
33            #[cfg(feature = "gas")]
34            gas: None,
35        }
36    }
37
38    #[cfg(feature = "remote")]
39    pub fn with_remote(mut self, remote: RemoteSteamUser) -> Self {
40        self.remote = Some(remote);
41        self
42    }
43
44    #[cfg(feature = "gas")]
45    pub fn with_gas(mut self, gas: GasSteamUser) -> Self {
46        self.gas = Some(gas);
47        self
48    }
49}
50
51// The `impl SteamUserApi for FallbackSteamUser` is generated from the canonical
52// method table in `crate::api_registry` via the `gen_fallback_impl!` callback.
53for_each_api_method!(gen_fallback_impl);