use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Region(
Cow<'static, str>,
);
impl AsRef<str> for Region {
fn as_ref(&self) -> &str {
&self.0
}
}
impl Display for Region {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl Storable for Region {
type Storer = StoreReplace<Region>;
}
impl Region {
pub fn new(region: impl Into<Cow<'static, str>>) -> Self {
Self(region.into())
}
pub const fn from_static(region: &'static str) -> Self {
Self(Cow::Borrowed(region))
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SigningRegion(Cow<'static, str>);
impl AsRef<str> for SigningRegion {
fn as_ref(&self) -> &str {
&self.0
}
}
impl From<Region> for SigningRegion {
fn from(inp: Region) -> Self {
SigningRegion(inp.0)
}
}
impl From<&'static str> for SigningRegion {
fn from(region: &'static str) -> Self {
Self::from_static(region)
}
}
impl SigningRegion {
pub const fn from_static(region: &'static str) -> Self {
SigningRegion(Cow::Borrowed(region))
}
}
impl Storable for SigningRegion {
type Storer = StoreReplace<Self>;
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SigningRegionSet(Cow<'static, str>);
impl From<Region> for SigningRegionSet {
fn from(inp: Region) -> Self {
SigningRegionSet(inp.0)
}
}
impl From<&'static str> for SigningRegionSet {
fn from(region: &'static str) -> Self {
SigningRegionSet(Cow::Borrowed(region))
}
}
impl<'a> FromIterator<&'a str> for SigningRegionSet {
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
let mut s = String::new();
let mut iter = iter.into_iter();
if let Some(region) = iter.next() {
s.push_str(region);
}
for region in iter {
s.push(',');
s.push_str(region);
}
SigningRegionSet(Cow::Owned(s))
}
}
impl Storable for SigningRegionSet {
type Storer = StoreReplace<Self>;
}
impl AsRef<str> for SigningRegionSet {
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}