Struct rivet_matchmaker::client::Client
source · [−]pub struct Client<C, M, R = Standard> { /* private fields */ }
Expand description
An ergonomic service client for MatchmakerService
.
This client allows ergonomic access to a MatchmakerService
-shaped service.
Each method corresponds to an endpoint defined in the service’s Smithy model,
and the request and response shapes are auto-generated from that same model.
Constructing a Client
To construct a client, you need a few different things:
- A
Config
that specifies additional configuration required by the service. - A connector (
C
) that specifies how HTTP requests are translated into HTTP responses. This will typically be an HTTP client (likehyper
), though you can also substitute in your own, like a mock mock connector for testing. - A “middleware” (
M
) that modifies requests prior to them being sent to the request. Most commonly, middleware will decide what endpoint the requests should be sent to, as well as perform authentication and authorization of requests (such as SigV4). You can also have middleware that performs request/response tracing, throttling, or other middleware-like tasks. - A retry policy (
R
) that dictates the behavior for requests that fail and should (potentially) be retried. The default type is generally what you want, as it implements a well-vetted retry policy implemented inRetryMode::Standard
.
To construct a client, you will generally want to call
Client::with_config
, which takes a aws_smithy_client::Client
(a
Smithy client that isn’t specialized to a particular service),
and a Config
. Both of these are constructed using
the builder pattern where you first construct a Builder
type,
then configure it with the necessary parameters, and then call
build
to construct the finalized output type. The
aws_smithy_client::Client
builder is re-exported in this crate as
Builder
for convenience.
In most circumstances, you will want to use the following pattern to construct a client:
use rivet_matchmaker::{Builder, Client, Config};
let raw_client =
Builder::dyn_https()
.middleware(/* discussed below */)
.build();
let config = Config::builder().build();
let client = Client::with_config(raw_client, config);
For the middleware, you’ll want to use whatever matches the routing, authentication and authorization required by the target service. For example, for the standard AWS SDK which uses SigV4-signed requests, the middleware looks like this:
use aws_endpoint::AwsEndpointStage;
use aws_http::auth::CredentialsStage;
use aws_http::recursion_detection::RecursionDetectionStage;
use aws_http::user_agent::UserAgentStage;
use aws_sig_auth::middleware::SigV4SigningStage;
use aws_sig_auth::signer::SigV4Signer;
use aws_smithy_client::retry::Config as RetryConfig;
use aws_smithy_http_tower::map_request::{AsyncMapRequestLayer, MapRequestLayer};
use std::fmt::Debug;
use tower::layer::util::{Identity, Stack};
use tower::ServiceBuilder;
type AwsMiddlewareStack = Stack<
MapRequestLayer<RecursionDetectionStage>,
Stack<
MapRequestLayer<SigV4SigningStage>,
Stack<
AsyncMapRequestLayer<CredentialsStage>,
Stack<
MapRequestLayer<UserAgentStage>,
Stack<MapRequestLayer<AwsEndpointStage>, Identity>,
>,
>,
>,
>;
/// AWS Middleware Stack
///
/// This implements the middleware stack for this service. It will:
/// 1. Load credentials asynchronously into the property bag
/// 2. Sign the request with SigV4
/// 3. Resolve an Endpoint for the request
/// 4. Add a user agent to the request
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct AwsMiddleware;
impl AwsMiddleware {
/// Create a new `AwsMiddleware` stack
///
/// Note: `AwsMiddleware` holds no state.
pub fn new() -> Self {
AwsMiddleware::default()
}
}
// define the middleware stack in a non-generic location to reduce code bloat.
fn base() -> ServiceBuilder<AwsMiddlewareStack> {
let credential_provider = AsyncMapRequestLayer::for_mapper(CredentialsStage::new());
let signer = MapRequestLayer::for_mapper(SigV4SigningStage::new(SigV4Signer::new()));
let endpoint_resolver = MapRequestLayer::for_mapper(AwsEndpointStage);
let user_agent = MapRequestLayer::for_mapper(UserAgentStage::new());
let recursion_detection = MapRequestLayer::for_mapper(RecursionDetectionStage::new());
// These layers can be considered as occurring in order, that is:
// 1. Resolve an endpoint
// 2. Add a user agent
// 3. Acquire credentials
// 4. Sign with credentials
// (5. Dispatch over the wire)
ServiceBuilder::new()
.layer(endpoint_resolver)
.layer(user_agent)
.layer(credential_provider)
.layer(signer)
.layer(recursion_detection)
}
impl<S> tower::Layer<S> for AwsMiddleware {
type Service = <AwsMiddlewareStack as tower::Layer<S>>::Service;
fn layer(&self, inner: S) -> Self::Service {
base().service(inner)
}
}
Using a Client
Once you have a client set up, you can access the service’s endpoints
by calling the appropriate method on Client
. Each such method
returns a request builder for that endpoint, with methods for setting
the various fields of the request. Once your request is complete, use
the send
method to send the request. send
returns a future, which
you then have to .await
to get the service’s response.
Implementations
sourceimpl<C, M, R> Client<C, M, R> where
C: SmithyConnector,
M: SmithyMiddleware<C>,
R: NewRequestPolicy,
impl<C, M, R> Client<C, M, R> where
C: SmithyConnector,
M: SmithyMiddleware<C>,
R: NewRequestPolicy,
sourcepub fn find_lobby(&self) -> FindLobby<C, M, R>
pub fn find_lobby(&self) -> FindLobby<C, M, R>
Constructs a fluent builder for the FindLobby
operation.
- The fluent builder is configurable:
game_modes(Vec<String>)
/set_game_modes(Option<Vec<String>>)
: Game modes to match lobbies against.regions(Vec<String>)
/set_regions(Option<Vec<String>>)
: Regions to match lobbies against. If not specified, the optimal region will be determined and will attempt to find lobbies in that region.prevent_auto_create_lobby(bool)
/set_prevent_auto_create_lobby(Option<bool>)
: Prevents a new lobby from being created when finding a lobby. If no lobby is found, aMATCHMAKER_LOBBY_NOT_FOUND
error will be thrown.captcha(CaptchaConfig)
/set_captcha(Option<CaptchaConfig>)
: Methods to verify a captcha.origin(impl Into<String>)
/set_origin(Option<String>)
: (undocumented)
- On success, responds with
FindLobbyOutput
with field(s):lobby(Option<MatchmakerLobbyJoinInfo>)
: A matchmaker lobby.
- On failure, responds with
SdkError<FindLobbyError>
sourcepub fn join_lobby(&self) -> JoinLobby<C, M, R>
pub fn join_lobby(&self) -> JoinLobby<C, M, R>
Constructs a fluent builder for the JoinLobby
operation.
- The fluent builder is configurable:
lobby_id(impl Into<String>)
/set_lobby_id(Option<String>)
: A universally unique identifier.captcha(CaptchaConfig)
/set_captcha(Option<CaptchaConfig>)
: Methods to verify a captcha.
- On success, responds with
JoinLobbyOutput
with field(s):lobby(Option<MatchmakerLobbyJoinInfo>)
: A matchmaker lobby.
- On failure, responds with
SdkError<JoinLobbyError>
sourcepub fn list_lobbies(&self) -> ListLobbies<C, M, R>
pub fn list_lobbies(&self) -> ListLobbies<C, M, R>
Constructs a fluent builder for the ListLobbies
operation.
- The fluent builder takes no input, just
send
it. - On success, responds with
ListLobbiesOutput
with field(s):game_modes(Option<Vec<GameModeInfo>>)
: (undocumented)regions(Option<Vec<RegionInfo>>)
: (undocumented)lobbies(Option<Vec<LobbyInfo>>)
: (undocumented)
- On failure, responds with
SdkError<ListLobbiesError>
sourcepub fn list_regions(&self) -> ListRegions<C, M, R>
pub fn list_regions(&self) -> ListRegions<C, M, R>
Constructs a fluent builder for the ListRegions
operation.
- The fluent builder takes no input, just
send
it. - On success, responds with
ListRegionsOutput
with field(s):regions(Option<Vec<RegionInfo>>)
: (undocumented)
- On failure, responds with
SdkError<ListRegionsError>
sourcepub fn lobby_ready(&self) -> LobbyReady<C, M, R>
pub fn lobby_ready(&self) -> LobbyReady<C, M, R>
Constructs a fluent builder for the LobbyReady
operation.
- The fluent builder takes no input, just
send
it. - On success, responds with
LobbyReadyOutput
- On failure, responds with
SdkError<LobbyReadyError>
sourcepub fn player_connected(&self) -> PlayerConnected<C, M, R>
pub fn player_connected(&self) -> PlayerConnected<C, M, R>
Constructs a fluent builder for the PlayerConnected
operation.
- The fluent builder is configurable:
player_token(impl Into<String>)
/set_player_token(Option<String>)
: A JSON Web Token. Slightly modified to include a description prefix and use Protobufs of JSON.
- On success, responds with
PlayerConnectedOutput
- On failure, responds with
SdkError<PlayerConnectedError>
sourcepub fn player_disconnected(&self) -> PlayerDisconnected<C, M, R>
pub fn player_disconnected(&self) -> PlayerDisconnected<C, M, R>
Constructs a fluent builder for the PlayerDisconnected
operation.
- The fluent builder is configurable:
player_token(impl Into<String>)
/set_player_token(Option<String>)
: A JSON Web Token. Slightly modified to include a description prefix and use Protobufs of JSON.
- On success, responds with
PlayerDisconnectedOutput
- On failure, responds with
SdkError<PlayerDisconnectedError>
sourcepub fn set_lobby_closed(&self) -> SetLobbyClosed<C, M, R>
pub fn set_lobby_closed(&self) -> SetLobbyClosed<C, M, R>
Constructs a fluent builder for the SetLobbyClosed
operation.
- The fluent builder is configurable:
is_closed(bool)
/set_is_closed(Option<bool>)
: (undocumented)
- On success, responds with
SetLobbyClosedOutput
- On failure, responds with
SdkError<SetLobbyClosedError>
Trait Implementations
Auto Trait Implementations
impl<C, M, R = Standard> !RefUnwindSafe for Client<C, M, R>
impl<C, M, R> Send for Client<C, M, R> where
C: Send + Sync,
M: Send + Sync,
R: Send + Sync,
impl<C, M, R> Sync for Client<C, M, R> where
C: Send + Sync,
M: Send + Sync,
R: Send + Sync,
impl<C, M, R> Unpin for Client<C, M, R>
impl<C, M, R = Standard> !UnwindSafe for Client<C, M, R>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more