Skip to content

Commit 3b4c144

Browse files
authored
fix(rust/catalyst-types): add serde::Serialize to UUID types (#147)
1 parent cb475a6 commit 3b4c144

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

rust/catalyst-types/src/uuid/uuid_v4.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use std::fmt::{Display, Formatter};
44
use super::{decode_cbor_uuid, INVALID_UUID};
55

66
/// Type representing a `UUIDv4`.
7-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, serde::Deserialize)]
7+
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
88
#[serde(from = "uuid::Uuid")]
9+
#[serde(into = "uuid::Uuid")]
910
pub struct UuidV4 {
1011
/// UUID
1112
uuid: uuid::Uuid,
@@ -69,6 +70,15 @@ impl From<uuid::Uuid> for UuidV4 {
6970
}
7071
}
7172

73+
/// Returns a `uuid::Uuid` from `UUIDv4`.
74+
///
75+
/// NOTE: This does not guarantee that the `UUID` is valid.
76+
impl From<UuidV4> for uuid::Uuid {
77+
fn from(value: UuidV4) -> Self {
78+
value.uuid
79+
}
80+
}
81+
7282
#[cfg(test)]
7383
mod tests {
7484
use coset::cbor::Value;

rust/catalyst-types/src/uuid/uuid_v7.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use std::fmt::{Display, Formatter};
44
use super::{decode_cbor_uuid, INVALID_UUID};
55

66
/// Type representing a `UUIDv7`.
7-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, serde::Deserialize)]
7+
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
88
#[serde(from = "uuid::Uuid")]
9+
#[serde(into = "uuid::Uuid")]
910
pub struct UuidV7 {
1011
/// UUID
1112
uuid: uuid::Uuid,
@@ -69,6 +70,15 @@ impl From<uuid::Uuid> for UuidV7 {
6970
}
7071
}
7172

73+
/// Returns a `uuid::Uuid` from `UUIDv7`.
74+
///
75+
/// NOTE: This does not guarantee that the `UUID` is valid.
76+
impl From<UuidV7> for uuid::Uuid {
77+
fn from(value: UuidV7) -> Self {
78+
value.uuid
79+
}
80+
}
81+
7282
#[cfg(test)]
7383
mod tests {
7484
use coset::cbor::Value;

0 commit comments

Comments
 (0)