rivet_chat/
config.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Service config.
3///
4pub struct Config {
5	pub(crate) auth: Option<String>,
6	pub(crate) uri: String,
7}
8impl std::fmt::Debug for Config {
9	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10		let mut config = f.debug_struct("Config");
11		config.finish()
12	}
13}
14impl Config {
15	/// Constructs a config builder.
16	pub fn builder() -> Builder {
17		Builder::default()
18	}
19}
20/// Builder for creating a `Config`.
21#[derive(Default)]
22pub struct Builder {
23	pub(crate) auth: Option<String>,
24	pub(crate) uri: Option<String>,
25}
26impl Builder {
27	/// Constructs a config builder.
28	pub fn new() -> Self {
29		Self::default()
30	}
31	/// Sets the bearer token to be used with the Smithy client.
32	pub fn set_bearer_token(mut self, bearer_token: impl std::fmt::Display) -> Self {
33		self.auth = Some(format!("Bearer {}", bearer_token));
34		self
35	}
36	/// Sets the base URI to be used with the Smithy client.
37	pub fn set_uri(mut self, uri: impl ToString) -> Self {
38		self.uri = Some(uri.to_string());
39		self
40	}
41	/// Builds a [`Config`].
42	pub fn build(self) -> Config {
43		Config {
44			auth: self
45				.auth
46				.or_else(|| std::env::var("RIVET_LOBBY_TOKEN").ok())
47				.or_else(|| std::env::var("RIVET_CLIENT_TOKEN").ok()),
48			uri: self
49				.uri
50				.or_else(|| std::env::var("RIVET_CHAT_API_URL").ok())
51				.unwrap_or_else(|| "https://chat.api.rivet.gg/v1".to_string()),
52		}
53	}
54	/// Builds a default [`Client`] from the given config.
55	pub fn build_client(self) -> crate::client::ClientWrapper {
56		let raw_client = aws_smithy_client::Builder::dyn_https()
57			.middleware(tower::layer::util::Identity::new())
58			.sleep_impl(None)
59			.build();
60		crate::client::ClientWrapper {
61			client: crate::Client::with_config(raw_client, self.build()),
62		}
63	}
64}