Skip to content

Commit e0c35c1

Browse files
committed
scylla-cql: introduce CqlTimeuuid type
Introduced a `CqlTimeuuid` type which is a wrapper for v1 uuids.
1 parent 8c20d39 commit e0c35c1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

scylla-cql/src/frame/value.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ pub enum MaybeUnset<V> {
5151
Set(V),
5252
}
5353

54+
/// Represents timeuuid (uuid V1) value
55+
#[derive(Debug, Clone, Copy)]
56+
pub struct CqlTimeuuid(Uuid);
57+
58+
impl std::str::FromStr for CqlTimeuuid {
59+
type Err = uuid::Error;
60+
61+
fn from_str(s: &str) -> Result<Self, Self::Err> {
62+
Ok(Self(Uuid::from_str(s)?))
63+
}
64+
}
65+
66+
impl AsRef<Uuid> for CqlTimeuuid {
67+
fn as_ref(&self) -> &Uuid {
68+
&self.0
69+
}
70+
}
71+
72+
impl From<CqlTimeuuid> for Uuid {
73+
fn from(value: CqlTimeuuid) -> Self {
74+
value.0
75+
}
76+
}
77+
78+
impl From<Uuid> for CqlTimeuuid {
79+
fn from(value: Uuid) -> Self {
80+
Self(value)
81+
}
82+
}
83+
5484
/// Native CQL date representation that allows for a bigger range of dates (-262145-1-1 to 262143-12-31).
5585
///
5686
/// Represented as number of days since -5877641-06-23 i.e. 2^31 days before unix epoch.

0 commit comments

Comments
 (0)