aws_smithy_types/
checksum_config.rs1use std::error::Error;
15use std::fmt;
16use std::str::FromStr;
17
18use crate::config_bag::{Storable, StoreReplace};
19
20const WHEN_SUPPORTED: &str = "when_supported";
22const WHEN_REQUIRED: &str = "when_required";
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
34#[non_exhaustive]
35pub enum RequestChecksumCalculation {
36 #[default]
38 WhenSupported,
39 WhenRequired,
41}
42
43impl Storable for RequestChecksumCalculation {
44 type Storer = StoreReplace<Self>;
45}
46
47impl FromStr for RequestChecksumCalculation {
48 type Err = UnknownRequestChecksumCalculationError;
49
50 fn from_str(request_checksum_calculation: &str) -> Result<Self, Self::Err> {
51 if request_checksum_calculation.eq_ignore_ascii_case(WHEN_SUPPORTED) {
52 Ok(Self::WhenSupported)
53 } else if request_checksum_calculation.eq_ignore_ascii_case(WHEN_REQUIRED) {
54 Ok(Self::WhenRequired)
55 } else {
56 Err(UnknownRequestChecksumCalculationError::new(
57 request_checksum_calculation,
58 ))
59 }
60 }
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
72#[non_exhaustive]
73pub enum ResponseChecksumValidation {
74 #[default]
76 WhenSupported,
77 WhenRequired,
79}
80
81impl Storable for ResponseChecksumValidation {
82 type Storer = StoreReplace<Self>;
83}
84
85impl FromStr for ResponseChecksumValidation {
86 type Err = UnknownResponseChecksumValidationError;
87
88 fn from_str(response_checksum_validation: &str) -> Result<Self, Self::Err> {
89 if response_checksum_validation.eq_ignore_ascii_case(WHEN_SUPPORTED) {
90 Ok(Self::WhenSupported)
91 } else if response_checksum_validation.eq_ignore_ascii_case(WHEN_REQUIRED) {
92 Ok(Self::WhenRequired)
93 } else {
94 Err(UnknownResponseChecksumValidationError::new(
95 response_checksum_validation,
96 ))
97 }
98 }
99}
100
101#[derive(Debug)]
103#[non_exhaustive]
104pub struct UnknownRequestChecksumCalculationError {
105 request_checksum_calculation: String,
106}
107
108impl UnknownRequestChecksumCalculationError {
109 pub(crate) fn new(request_checksum_calculation: impl Into<String>) -> Self {
110 Self {
111 request_checksum_calculation: request_checksum_calculation.into(),
112 }
113 }
114
115 pub fn request_checksum_calculation(&self) -> &str {
117 &self.request_checksum_calculation
118 }
119}
120
121impl fmt::Display for UnknownRequestChecksumCalculationError {
122 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123 write!(
124 f,
125 r#"unknown request_checksum_calculation value "{}", please pass a known name ("when_supported", "when_required")"#,
126 self.request_checksum_calculation
127 )
128 }
129}
130
131impl Error for UnknownRequestChecksumCalculationError {}
132
133#[derive(Debug)]
135#[non_exhaustive]
136pub struct UnknownResponseChecksumValidationError {
137 response_checksum_validation: String,
138}
139
140impl UnknownResponseChecksumValidationError {
141 pub(crate) fn new(response_checksum_validation: impl Into<String>) -> Self {
142 Self {
143 response_checksum_validation: response_checksum_validation.into(),
144 }
145 }
146
147 pub fn response_checksum_validation(&self) -> &str {
149 &self.response_checksum_validation
150 }
151}
152
153impl fmt::Display for UnknownResponseChecksumValidationError {
154 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
155 write!(
156 f,
157 r#"unknown response_checksum_validation value "{}", please pass a known name ("when_supported", "when_required")"#,
158 self.response_checksum_validation
159 )
160 }
161}
162
163impl Error for UnknownResponseChecksumValidationError {}