fts_core/
models.rs

1mod auction;
2mod auth;
3mod bound;
4mod config;
5mod cost;
6mod datetime;
7mod demand;
8mod outcome;
9mod product;
10mod submission;
11
12pub use auction::{AuctionMetaData, AuctionSolveRequest, RawAuctionInput};
13pub use auth::{AuthData, AuthHistoryRecord, AuthId, AuthRecord, Portfolio};
14pub use bound::Bound;
15pub use config::Config;
16pub use cost::{CostData, CostHistoryRecord, CostId, CostRecord, Group, GroupDisplay};
17pub use datetime::{DateTimeRangeQuery, DateTimeRangeResponse};
18pub use demand::{Constant, Curve, DemandCurve, Point};
19pub use outcome::{AuctionOutcome, Outcome};
20pub use product::{ProductData, ProductQuery, ProductQueryResponse, ProductRecord};
21pub use submission::SubmissionRecord;
22
23macro_rules! uuid_wrapper {
24    ($struct: ident) => {
25        /// A UUID newtype
26        #[derive(
27            Debug,
28            Hash,
29            PartialEq,
30            Eq,
31            Clone,
32            Copy,
33            serde::Serialize,
34            serde::Deserialize,
35            PartialOrd,
36            Ord,
37            utoipa::ToSchema,
38        )]
39        #[serde(transparent)]
40        #[repr(transparent)]
41        pub struct $struct(uuid::Uuid);
42
43        impl From<uuid::Uuid> for $struct {
44            fn from(value: uuid::Uuid) -> Self {
45                Self(value)
46            }
47        }
48
49        impl Into<uuid::Uuid> for $struct {
50            fn into(self) -> uuid::Uuid {
51                self.0
52            }
53        }
54
55        impl TryFrom<&str> for $struct {
56            type Error = <uuid::Uuid as std::str::FromStr>::Err;
57
58            fn try_from(value: &str) -> Result<Self, Self::Error> {
59                Ok(Self(<uuid::Uuid as std::str::FromStr>::from_str(value)?))
60            }
61        }
62
63        impl Into<String> for $struct {
64            fn into(self) -> String {
65                self.0.to_string()
66            }
67        }
68
69        impl std::ops::Deref for $struct {
70            type Target = uuid::Uuid;
71
72            fn deref(&self) -> &Self::Target {
73                &self.0
74            }
75        }
76
77        impl std::fmt::Display for $struct {
78            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79                self.0.fmt(f)
80            }
81        }
82    };
83}
84
85pub(crate) use uuid_wrapper;
86uuid_wrapper!(BidderId);
87uuid_wrapper!(ProductId);
88
89macro_rules! map_wrapper {
90    ($struct:ident, $key:ty, $value:ty) => {
91        /// A hashmap with deterministic ordering
92        #[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
93        #[serde(transparent)]
94        #[schema(value_type = std::collections::HashMap<$key, $value>)]
95        pub struct $struct(pub indexmap::IndexMap<$key, $value, rustc_hash::FxBuildHasher>);
96
97        impl std::ops::Deref for $struct {
98            type Target = indexmap::IndexMap<$key, $value, rustc_hash::FxBuildHasher>;
99
100            fn deref(&self) -> &Self::Target {
101                &self.0
102            }
103        }
104
105        impl IntoIterator for $struct {
106            type Item = ($key, $value);
107            type IntoIter = indexmap::map::IntoIter<$key, $value>;
108            /// Forward the into_iter() implementation from the newtype
109            fn into_iter(self) -> Self::IntoIter {
110                self.0.into_iter()
111            }
112        }
113
114        impl FromIterator<($key, $value)> for $struct {
115            fn from_iter<I: IntoIterator<Item = ($key, $value)>>(iter: I) -> Self {
116                Self(indexmap::IndexMap::from_iter(iter))
117            }
118        }
119    };
120}
121
122pub(crate) use map_wrapper;