Skip to main content

aws_sdk_iam/types/
_tag.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// <p>A structure that represents user-provided metadata that can be associated with an IAM resource. For more information about tagging, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html">Tagging IAM resources</a> in the <i>IAM User Guide</i>.</p>
4#[non_exhaustive]
5#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
6pub struct Tag {
7    /// <p>The key name that can be used to look up or retrieve the associated value. For example, <code>Department</code> or <code>Cost Center</code> are common choices.</p>
8    pub key: ::std::string::String,
9    /// <p>The value associated with this tag. For example, tags with a key name of <code>Department</code> could have values such as <code>Human Resources</code>, <code>Accounting</code>, and <code>Support</code>. Tags with a key name of <code>Cost Center</code> might have values that consist of the number associated with the different cost centers in your company. Typically, many resources have tags with the same key name but with different values.</p>
10    pub value: ::std::string::String,
11}
12impl Tag {
13    /// <p>The key name that can be used to look up or retrieve the associated value. For example, <code>Department</code> or <code>Cost Center</code> are common choices.</p>
14    pub fn key(&self) -> &str {
15        use std::ops::Deref;
16        self.key.deref()
17    }
18    /// <p>The value associated with this tag. For example, tags with a key name of <code>Department</code> could have values such as <code>Human Resources</code>, <code>Accounting</code>, and <code>Support</code>. Tags with a key name of <code>Cost Center</code> might have values that consist of the number associated with the different cost centers in your company. Typically, many resources have tags with the same key name but with different values.</p>
19    pub fn value(&self) -> &str {
20        use std::ops::Deref;
21        self.value.deref()
22    }
23}
24impl Tag {
25    /// Creates a new builder-style object to manufacture [`Tag`](crate::types::Tag).
26    pub fn builder() -> crate::types::builders::TagBuilder {
27        crate::types::builders::TagBuilder::default()
28    }
29}
30
31/// A builder for [`Tag`](crate::types::Tag).
32#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
33#[non_exhaustive]
34pub struct TagBuilder {
35    pub(crate) key: ::std::option::Option<::std::string::String>,
36    pub(crate) value: ::std::option::Option<::std::string::String>,
37}
38impl TagBuilder {
39    /// <p>The key name that can be used to look up or retrieve the associated value. For example, <code>Department</code> or <code>Cost Center</code> are common choices.</p>
40    /// This field is required.
41    pub fn key(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
42        self.key = ::std::option::Option::Some(input.into());
43        self
44    }
45    /// <p>The key name that can be used to look up or retrieve the associated value. For example, <code>Department</code> or <code>Cost Center</code> are common choices.</p>
46    pub fn set_key(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
47        self.key = input;
48        self
49    }
50    /// <p>The key name that can be used to look up or retrieve the associated value. For example, <code>Department</code> or <code>Cost Center</code> are common choices.</p>
51    pub fn get_key(&self) -> &::std::option::Option<::std::string::String> {
52        &self.key
53    }
54    /// <p>The value associated with this tag. For example, tags with a key name of <code>Department</code> could have values such as <code>Human Resources</code>, <code>Accounting</code>, and <code>Support</code>. Tags with a key name of <code>Cost Center</code> might have values that consist of the number associated with the different cost centers in your company. Typically, many resources have tags with the same key name but with different values.</p>
55    /// This field is required.
56    pub fn value(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
57        self.value = ::std::option::Option::Some(input.into());
58        self
59    }
60    /// <p>The value associated with this tag. For example, tags with a key name of <code>Department</code> could have values such as <code>Human Resources</code>, <code>Accounting</code>, and <code>Support</code>. Tags with a key name of <code>Cost Center</code> might have values that consist of the number associated with the different cost centers in your company. Typically, many resources have tags with the same key name but with different values.</p>
61    pub fn set_value(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
62        self.value = input;
63        self
64    }
65    /// <p>The value associated with this tag. For example, tags with a key name of <code>Department</code> could have values such as <code>Human Resources</code>, <code>Accounting</code>, and <code>Support</code>. Tags with a key name of <code>Cost Center</code> might have values that consist of the number associated with the different cost centers in your company. Typically, many resources have tags with the same key name but with different values.</p>
66    pub fn get_value(&self) -> &::std::option::Option<::std::string::String> {
67        &self.value
68    }
69    /// Consumes the builder and constructs a [`Tag`](crate::types::Tag).
70    /// This method will fail if any of the following fields are not set:
71    /// - [`key`](crate::types::builders::TagBuilder::key)
72    /// - [`value`](crate::types::builders::TagBuilder::value)
73    pub fn build(self) -> ::std::result::Result<crate::types::Tag, ::aws_smithy_types::error::operation::BuildError> {
74        ::std::result::Result::Ok(crate::types::Tag {
75            key: self.key.ok_or_else(|| {
76                ::aws_smithy_types::error::operation::BuildError::missing_field("key", "key was not specified but it is required when building Tag")
77            })?,
78            value: self.value.ok_or_else(|| {
79                ::aws_smithy_types::error::operation::BuildError::missing_field(
80                    "value",
81                    "value was not specified but it is required when building Tag",
82                )
83            })?,
84        })
85    }
86}