Skip to main content

nominal_api/conjure/objects/api/
token.rs

1/// Tokens are used with paginated requests to get the next "page" of results
2/// from an API, and typically are used as both part of the request and response
3/// schema of an endpoint to allow users to stream pages of results.
4#[derive(
5    Debug,
6    Clone,
7    conjure_object::serde::Deserialize,
8    conjure_object::serde::Serialize,
9    PartialEq,
10    Eq,
11    PartialOrd,
12    Ord,
13    Hash,
14    Default
15)]
16#[serde(crate = "conjure_object::serde", transparent)]
17pub struct Token(pub String);
18impl std::fmt::Display for Token {
19    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        std::fmt::Display::fmt(&self.0, fmt)
21    }
22}
23impl conjure_object::Plain for Token {
24    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        conjure_object::Plain::fmt(&self.0, fmt)
26    }
27}
28impl conjure_object::FromPlain for Token {
29    type Err = <String as conjure_object::FromPlain>::Err;
30    #[inline]
31    fn from_plain(s: &str) -> Result<Token, Self::Err> {
32        conjure_object::FromPlain::from_plain(s).map(Token)
33    }
34}
35impl std::convert::From<String> for Token {
36    #[inline]
37    fn from(v: String) -> Self {
38        Token(std::convert::From::from(v))
39    }
40}
41impl std::ops::Deref for Token {
42    type Target = String;
43    #[inline]
44    fn deref(&self) -> &String {
45        &self.0
46    }
47}
48impl std::ops::DerefMut for Token {
49    #[inline]
50    fn deref_mut(&mut self) -> &mut String {
51        &mut self.0
52    }
53}
54impl std::convert::AsRef<String> for Token {
55    #[inline]
56    fn as_ref(&self) -> &String {
57        &self.0
58    }
59}