diff options
Diffstat (limited to 'crates/rocie-server/src/storage/sql/unit.rs')
| -rw-r--r-- | crates/rocie-server/src/storage/sql/unit.rs | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/crates/rocie-server/src/storage/sql/unit.rs b/crates/rocie-server/src/storage/sql/unit.rs index fe00b1b..77e7a2e 100644 --- a/crates/rocie-server/src/storage/sql/unit.rs +++ b/crates/rocie-server/src/storage/sql/unit.rs @@ -17,23 +17,44 @@ pub(crate) struct Unit { #[derive( Deserialize, Serialize, Debug, Default, ToSchema, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, )] -pub(crate) struct UnitId(Uuid); +pub(crate) struct UnitId { + value: Uuid, +} + +#[derive(Deserialize, Serialize, Debug, Clone, Copy)] +#[serde(from = "Uuid")] +pub(crate) struct UnitIdStub { + value: Uuid, +} impl UnitId { pub(crate) fn from_db(id: &str) -> UnitId { - Self(Uuid::from_str(id).expect("We put an uuid into the db, it should also go out again")) + Self { + value: Uuid::from_str(id) + .expect("We put an uuid into the db, it should also go out again"), + } } } impl Display for UnitId { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) + write!(f, "{}", self.value) } } impl From<Uuid> for UnitId { fn from(value: Uuid) -> Self { - Self(value) + Self { value } + } +} +impl From<Uuid> for UnitIdStub { + fn from(value: Uuid) -> Self { + Self { value } + } +} +impl From<UnitIdStub> for UnitId { + fn from(value: UnitIdStub) -> Self { + Self { value: value.value } } } @@ -45,7 +66,7 @@ where &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> { - let inner = self.0.to_string(); + let inner = self.value.to_string(); Encode::<DB>::encode_by_ref(&inner, buf) } } |
