Skip to main content

tmdb_rs/
credentials.rs

1use std::fmt;
2
3macro_rules! credential {
4    ($(#[$meta:meta])* $name:ident) => {
5        $(#[$meta])*
6        #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
7        pub struct $name(String);
8
9        impl $name {
10            pub fn new(value: impl Into<String>) -> Self {
11                Self(value.into())
12            }
13
14            pub fn as_str(&self) -> &str {
15                &self.0
16            }
17        }
18
19        impl fmt::Display for $name {
20            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21                f.write_str(&self.0)
22            }
23        }
24    };
25}
26
27credential! {
28    /// a v3 session id, from the authentication flow
29    SessionId
30}
31
32#[cfg(feature = "v4")]
33credential! {
34    /// a v4 user access token, from the v4 auth flow
35    AccessToken
36}
37
38credential! {
39    /// a v3 guest session id
40    GuestSessionId
41}