aws_sdk_pinpointsmsvoicev2/types/
_text_validation.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// <p>Validation rules for a text field.</p>
4#[non_exhaustive]
5#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
6pub struct TextValidation {
7    /// <p>The minimum number of characters for the text field.</p>
8    pub min_length: i32,
9    /// <p>The maximum number of characters for the text field.</p>
10    pub max_length: i32,
11    /// <p>The regular expression used to validate the text field.</p>
12    pub pattern: ::std::string::String,
13}
14impl TextValidation {
15    /// <p>The minimum number of characters for the text field.</p>
16    pub fn min_length(&self) -> i32 {
17        self.min_length
18    }
19    /// <p>The maximum number of characters for the text field.</p>
20    pub fn max_length(&self) -> i32 {
21        self.max_length
22    }
23    /// <p>The regular expression used to validate the text field.</p>
24    pub fn pattern(&self) -> &str {
25        use std::ops::Deref;
26        self.pattern.deref()
27    }
28}
29impl TextValidation {
30    /// Creates a new builder-style object to manufacture [`TextValidation`](crate::types::TextValidation).
31    pub fn builder() -> crate::types::builders::TextValidationBuilder {
32        crate::types::builders::TextValidationBuilder::default()
33    }
34}
35
36/// A builder for [`TextValidation`](crate::types::TextValidation).
37#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
38#[non_exhaustive]
39pub struct TextValidationBuilder {
40    pub(crate) min_length: ::std::option::Option<i32>,
41    pub(crate) max_length: ::std::option::Option<i32>,
42    pub(crate) pattern: ::std::option::Option<::std::string::String>,
43}
44impl TextValidationBuilder {
45    /// <p>The minimum number of characters for the text field.</p>
46    /// This field is required.
47    pub fn min_length(mut self, input: i32) -> Self {
48        self.min_length = ::std::option::Option::Some(input);
49        self
50    }
51    /// <p>The minimum number of characters for the text field.</p>
52    pub fn set_min_length(mut self, input: ::std::option::Option<i32>) -> Self {
53        self.min_length = input;
54        self
55    }
56    /// <p>The minimum number of characters for the text field.</p>
57    pub fn get_min_length(&self) -> &::std::option::Option<i32> {
58        &self.min_length
59    }
60    /// <p>The maximum number of characters for the text field.</p>
61    /// This field is required.
62    pub fn max_length(mut self, input: i32) -> Self {
63        self.max_length = ::std::option::Option::Some(input);
64        self
65    }
66    /// <p>The maximum number of characters for the text field.</p>
67    pub fn set_max_length(mut self, input: ::std::option::Option<i32>) -> Self {
68        self.max_length = input;
69        self
70    }
71    /// <p>The maximum number of characters for the text field.</p>
72    pub fn get_max_length(&self) -> &::std::option::Option<i32> {
73        &self.max_length
74    }
75    /// <p>The regular expression used to validate the text field.</p>
76    /// This field is required.
77    pub fn pattern(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
78        self.pattern = ::std::option::Option::Some(input.into());
79        self
80    }
81    /// <p>The regular expression used to validate the text field.</p>
82    pub fn set_pattern(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
83        self.pattern = input;
84        self
85    }
86    /// <p>The regular expression used to validate the text field.</p>
87    pub fn get_pattern(&self) -> &::std::option::Option<::std::string::String> {
88        &self.pattern
89    }
90    /// Consumes the builder and constructs a [`TextValidation`](crate::types::TextValidation).
91    /// This method will fail if any of the following fields are not set:
92    /// - [`min_length`](crate::types::builders::TextValidationBuilder::min_length)
93    /// - [`max_length`](crate::types::builders::TextValidationBuilder::max_length)
94    /// - [`pattern`](crate::types::builders::TextValidationBuilder::pattern)
95    pub fn build(self) -> ::std::result::Result<crate::types::TextValidation, ::aws_smithy_types::error::operation::BuildError> {
96        ::std::result::Result::Ok(crate::types::TextValidation {
97            min_length: self.min_length.ok_or_else(|| {
98                ::aws_smithy_types::error::operation::BuildError::missing_field(
99                    "min_length",
100                    "min_length was not specified but it is required when building TextValidation",
101                )
102            })?,
103            max_length: self.max_length.ok_or_else(|| {
104                ::aws_smithy_types::error::operation::BuildError::missing_field(
105                    "max_length",
106                    "max_length was not specified but it is required when building TextValidation",
107                )
108            })?,
109            pattern: self.pattern.ok_or_else(|| {
110                ::aws_smithy_types::error::operation::BuildError::missing_field(
111                    "pattern",
112                    "pattern was not specified but it is required when building TextValidation",
113                )
114            })?,
115        })
116    }
117}