stedi_sdk_client_guides/
endpoint.rs1#[cfg(test)]
5mod test {}
6
7#[non_exhaustive]
8#[derive(std::clone::Clone, std::cmp::PartialEq, std::fmt::Debug)]
9pub struct Params {
11 pub(crate) region: std::string::String,
13 pub(crate) stage: std::option::Option<std::string::String>,
14 pub(crate) endpoint: std::option::Option<std::string::String>,
16}
17impl Params {
18 pub fn builder() -> crate::endpoint::ParamsBuilder {
20 crate::endpoint::ParamsBuilder::default()
21 }
22 pub fn region(&self) -> std::option::Option<&str> {
24 Some(&self.region)
25 }
26 pub fn stage(&self) -> std::option::Option<&str> {
28 self.stage.as_deref()
29 }
30 pub fn endpoint(&self) -> std::option::Option<&str> {
32 self.endpoint.as_deref()
33 }
34}
35
36#[derive(Default)]
38pub struct DefaultResolver {}
39
40impl DefaultResolver {
41 pub fn new() -> Self {
43 Self {}
44 }
45}
46
47impl aws_smithy_http::endpoint::ResolveEndpoint<crate::endpoint::Params> for DefaultResolver {
48 fn resolve_endpoint(&self, params: &Params) -> aws_smithy_http::endpoint::Result {
49 let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new();
50 crate::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector)
51 .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))
52 }
53}
54
55#[derive(std::clone::Clone, std::cmp::PartialEq, std::default::Default, std::fmt::Debug)]
57pub struct ParamsBuilder {
58 region: std::option::Option<std::string::String>,
59 stage: std::option::Option<std::string::String>,
60 endpoint: std::option::Option<std::string::String>,
61}
62impl ParamsBuilder {
63 pub fn build(self) -> Result<crate::endpoint::Params, crate::endpoint::InvalidParams> {
65 Ok(
66 #[allow(clippy::unnecessary_lazy_evaluations)]
67 crate::endpoint::Params {
68 region: self
69 .region
70 .or_else(|| Some("us".to_string()))
71 .ok_or_else(|| crate::endpoint::InvalidParams::missing("region"))?,
72 stage: self.stage,
73 endpoint: self.endpoint,
74 },
75 )
76 }
77 pub fn region(mut self, value: impl Into<std::string::String>) -> Self {
82 self.region = Some(value.into());
83 self
84 }
85
86 pub fn set_region(mut self, param: Option<std::string::String>) -> Self {
91 self.region = param;
92 self
93 }
94 pub fn stage(mut self, value: impl Into<std::string::String>) -> Self {
96 self.stage = Some(value.into());
97 self
98 }
99
100 pub fn set_stage(mut self, param: Option<std::string::String>) -> Self {
102 self.stage = param;
103 self
104 }
105 pub fn endpoint(mut self, value: impl Into<std::string::String>) -> Self {
109 self.endpoint = Some(value.into());
110 self
111 }
112
113 pub fn set_endpoint(mut self, param: Option<std::string::String>) -> Self {
117 self.endpoint = param;
118 self
119 }
120}
121
122#[derive(Debug)]
124pub struct InvalidParams {
125 field: std::borrow::Cow<'static, str>,
126}
127
128impl InvalidParams {
129 #[allow(dead_code)]
130 fn missing(field: &'static str) -> Self {
131 Self {
132 field: field.into(),
133 }
134 }
135}
136
137impl std::fmt::Display for InvalidParams {
138 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
139 write!(f, "a required field was missing: `{}`", self.field)
140 }
141}
142
143impl std::error::Error for InvalidParams {}
144
145mod internals;