Expand description
Type-safe operations on AWS tags.
§Overview
This basic data structure of this module is the TagList
struct. It contains
a list of untyped AWS tags. It implements TryFrom
and Into
for the relevant
Tag
types in the aws_sdk_*
crates. In itself, that is not too interesting,
as the tag values are still just String
.
To get typed tags, there is a Tags
macro. Applied to a struct, it adds
methods to create a struct instance for an instance TagList
, and turn a
struct instance back into a TagList
:
use aws_lib::tags::{Tags, TagList, RawTag};
#[Tags]
struct MyTags {
tag1: String,
tag2: bool,
tag3: Option<bool>,
}
let tags = TagList::from_vec(vec![
RawTag::new("tag1".to_owned(), "foo".to_owned()),
RawTag::new("tag2".to_owned(), "true".to_owned()),
]);
let parsed = MyTags::from_tags(tags).unwrap();
assert!(parsed.tag1 == "foo");
assert!(parsed.tag2);
assert!(parsed.tag3.is_none());
§Using custom tag types
By default, encoding and decoding of tags is supported for String
and bool
values.
String
is encoded as-isbool
is encoded astrue
andfalse
In case you have your own type T
you want to encode in a tag, there are two
strategies:
serde
, which requiresT
to implementSerialize
andDeserialize
.manual
, which requiresT
to impelemnt two traits:impl TryFrom<RawTagValue> for T
: How to (fallibly) create aT
from the value of an tagimpl From<T> for RawTagValue
: How to turnT
back into the value of a tag. This cannot fail.
There is a Tag
derive macro that selects the strategy, which can then
be used in a struct that is using #[Tags]
:
use aws_lib::tags::{Tag, Tags};
#[derive(Tag, Debug, Clone, PartialEq, Eq)]
#[tag(translate = transparent)]
struct MyTag(String);
#[Tags]
struct MyTags {
foo: MyTag,
}
Structs§
- RawTag
- RawTag
Value - Tag
- A tag generic over its containing value type.
- TagKey
- TagList
- Translate
Manual
Enums§
- Parse
TagAws Error - Parse
TagError - Like
ParseTagValueError
, but contains potential additional information about the tag key. - Parse
TagValue Error - Parse
Tags Error - Errors that can happen when parsing a set of tags.