funpay_client/models/
ids.rs

1use std::borrow::Borrow;
2use std::fmt::{Display, Formatter};
3use std::ops::Deref;
4
5macro_rules! define_string_id {
6    ($name:ident) => {
7        #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
8        pub struct $name(pub String);
9
10        impl From<String> for $name {
11            fn from(value: String) -> Self {
12                Self(value)
13            }
14        }
15
16        impl From<&str> for $name {
17            fn from(value: &str) -> Self {
18                Self(value.to_string())
19            }
20        }
21
22        impl Display for $name {
23            fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
24                Display::fmt(self.0.as_str(), f)
25            }
26        }
27
28        impl Deref for $name {
29            type Target = str;
30            fn deref(&self) -> &Self::Target {
31                self.0.as_str()
32            }
33        }
34
35        impl AsRef<str> for $name {
36            fn as_ref(&self) -> &str {
37                self.0.as_str()
38            }
39        }
40
41        impl Borrow<str> for $name {
42            fn borrow(&self) -> &str {
43                self.0.as_str()
44            }
45        }
46    };
47}
48
49define_string_id!(OrderId);
50define_string_id!(ChatId);
51define_string_id!(LotId);