1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

//! Types representing specific pieces of data contained within credentials or within token

/// Type representing a unique identifier representing an AWS account.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AccountId {
    inner: String,
}

impl AccountId {
    /// Return the string equivalent of this account id.
    pub fn as_str(&self) -> &str {
        &self.inner
    }
}

impl<T> From<T> for AccountId
where
    T: Into<String>,
{
    fn from(value: T) -> Self {
        Self {
            inner: value.into(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn account_id_creation() {
        let expected = "012345678901";
        assert_eq!(expected, AccountId::from(expected).as_str());
        assert_eq!(expected, AccountId::from(String::from(expected)).as_str());
    }
}