stedi_sdk_client_guides/
endpoint.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// Generated endpoint tests
4#[cfg(test)]
5mod test {}
6
7#[non_exhaustive]
8#[derive(std::clone::Clone, std::cmp::PartialEq, std::fmt::Debug)]
9/// Configuration parameters for resolving the correct endpoint
10pub struct Params {
11    /// The region to dispatch this request, eg. `us`.
12    pub(crate) region: std::string::String,
13    pub(crate) stage: std::option::Option<std::string::String>,
14    /// Override the endpoint used to send this request
15    pub(crate) endpoint: std::option::Option<std::string::String>,
16}
17impl Params {
18    /// Create a builder for [`Params`]
19    pub fn builder() -> crate::endpoint::ParamsBuilder {
20        crate::endpoint::ParamsBuilder::default()
21    }
22    /// The region to dispatch this request, eg. `us`.
23    pub fn region(&self) -> std::option::Option<&str> {
24        Some(&self.region)
25    }
26    /// Gets the value for `stage`
27    pub fn stage(&self) -> std::option::Option<&str> {
28        self.stage.as_deref()
29    }
30    /// Override the endpoint used to send this request
31    pub fn endpoint(&self) -> std::option::Option<&str> {
32        self.endpoint.as_deref()
33    }
34}
35
36/// The default endpoint resolver
37#[derive(Default)]
38pub struct DefaultResolver {}
39
40impl DefaultResolver {
41    /// Create a new endpoint resolver with default settings
42    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/// Builder for [`Params`]
56#[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    /// Consume this builder, creating [`Params`].
64    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    /// Sets the value for region
78    ///
79    /// When unset, this parameter has a default value of `us`.
80    /// The region to dispatch this request, eg. `us`.
81    pub fn region(mut self, value: impl Into<std::string::String>) -> Self {
82        self.region = Some(value.into());
83        self
84    }
85
86    /// Sets the value for region
87    ///
88    /// When unset, this parameter has a default value of `us`.
89    /// The region to dispatch this request, eg. `us`.
90    pub fn set_region(mut self, param: Option<std::string::String>) -> Self {
91        self.region = param;
92        self
93    }
94    /// Sets the value for stage
95    pub fn stage(mut self, value: impl Into<std::string::String>) -> Self {
96        self.stage = Some(value.into());
97        self
98    }
99
100    /// Sets the value for stage
101    pub fn set_stage(mut self, param: Option<std::string::String>) -> Self {
102        self.stage = param;
103        self
104    }
105    /// Sets the value for endpoint
106    ///
107    /// Override the endpoint used to send this request
108    pub fn endpoint(mut self, value: impl Into<std::string::String>) -> Self {
109        self.endpoint = Some(value.into());
110        self
111    }
112
113    /// Sets the value for endpoint
114    ///
115    /// Override the endpoint used to send this request
116    pub fn set_endpoint(mut self, param: Option<std::string::String>) -> Self {
117        self.endpoint = param;
118        self
119    }
120}
121
122/// An error that occurred during endpoint resolution
123#[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
145/// Endpoints internals
146mod internals;