From e536cb326a67fffd511ead4a87655ca5ef98bf29 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 23 Sep 2025 17:16:23 +0200 Subject: feat(crates/rocies-server): Don't make the newtype wrappers transparent in the openapi spec This makes using the generated code significantly easier and type safer. --- crates/rocie-server/src/storage/sql/unit.rs | 31 ++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'crates/rocie-server/src/storage/sql/unit.rs') 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 for UnitId { fn from(value: Uuid) -> Self { - Self(value) + Self { value } + } +} +impl From for UnitIdStub { + fn from(value: Uuid) -> Self { + Self { value } + } +} +impl From for UnitId { + fn from(value: UnitIdStub) -> Self { + Self { value: value.value } } } @@ -45,7 +66,7 @@ where &self, buf: &mut ::ArgumentBuffer<'q>, ) -> Result { - let inner = self.0.to_string(); + let inner = self.value.to_string(); Encode::::encode_by_ref(&inner, buf) } } -- cgit 1.4.1