From ad6ee5b42d6192168324d4daeaf696a334b83559 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 19 Oct 2022 10:55:19 +0100 Subject: [PATCH] Add some additional code comments --- lib/src/sql/datetime.rs | 1 + lib/src/sql/duration.rs | 13 +++++++------ lib/src/sql/graph.rs | 1 + lib/src/sql/id.rs | 2 ++ lib/src/sql/ident.rs | 1 + lib/src/sql/part.rs | 2 +- lib/src/sql/strand.rs | 3 +++ lib/src/sql/thing.rs | 1 + lib/src/sql/uuid.rs | 4 ++++ 9 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/src/sql/datetime.rs b/lib/src/sql/datetime.rs index f51e7a44..3a07b83c 100644 --- a/lib/src/sql/datetime.rs +++ b/lib/src/sql/datetime.rs @@ -52,6 +52,7 @@ impl Deref for Datetime { } impl Datetime { + /// Convert the Datetime to a raw String pub fn to_raw(&self) -> String { self.0.to_rfc3339_opts(SecondsFormat::AutoSi, true) } diff --git a/lib/src/sql/duration.rs b/lib/src/sql/duration.rs index 9d1aa87e..ae4a90b2 100644 --- a/lib/src/sql/duration.rs +++ b/lib/src/sql/duration.rs @@ -52,38 +52,39 @@ impl Deref for Duration { } impl Duration { + /// Convert the Duration to a raw String pub fn to_raw(&self) -> String { self.to_string() } - + /// Get the total number of seconds pub fn secs(&self) -> Value { self.0.as_secs().into() } - + /// Get the total number of minutes pub fn mins(&self) -> Value { let secs = self.0.as_secs(); let mins = secs / SECONDS_PER_MINUTE; mins.into() } - + /// Get the total number of hours pub fn hours(&self) -> Value { let secs = self.0.as_secs(); let hours = secs / SECONDS_PER_HOUR; hours.into() } - + /// Get the total number of dats pub fn days(&self) -> Value { let secs = self.0.as_secs(); let days = secs / SECONDS_PER_DAY; days.into() } - + /// Get the total number of months pub fn weeks(&self) -> Value { let secs = self.0.as_secs(); let weeks = secs / SECONDS_PER_WEEK; weeks.into() } - + /// Get the total number of years pub fn years(&self) -> Value { let secs = self.0.as_secs(); let years = secs / SECONDS_PER_YEAR; diff --git a/lib/src/sql/graph.rs b/lib/src/sql/graph.rs index d8a3c6a4..ce4eef4f 100644 --- a/lib/src/sql/graph.rs +++ b/lib/src/sql/graph.rs @@ -22,6 +22,7 @@ pub struct Graph { } impl Graph { + /// Convert the graph edge to a raw String pub fn to_raw(&self) -> String { self.to_string() } diff --git a/lib/src/sql/id.rs b/lib/src/sql/id.rs index 852e71f1..64f54cfe 100644 --- a/lib/src/sql/id.rs +++ b/lib/src/sql/id.rs @@ -83,9 +83,11 @@ impl From> for Id { } impl Id { + /// Generate a new random ID pub fn rand() -> Self { Self::String(nanoid!(20, &ID_CHARS)) } + /// Convert the Id to a raw String pub fn to_raw(&self) -> String { match self { Self::Number(v) => v.to_string(), diff --git a/lib/src/sql/ident.rs b/lib/src/sql/ident.rs index a6b22d19..7f0d68d0 100644 --- a/lib/src/sql/ident.rs +++ b/lib/src/sql/ident.rs @@ -44,6 +44,7 @@ impl Deref for Ident { } impl Ident { + /// Convert the Ident to a raw String pub fn to_raw(&self) -> String { self.0.to_string() } diff --git a/lib/src/sql/part.rs b/lib/src/sql/part.rs index 814b50e6..55d82afd 100644 --- a/lib/src/sql/part.rs +++ b/lib/src/sql/part.rs @@ -91,7 +91,7 @@ impl From<&str> for Part { } impl Part { - // Returns a yield if an alias is specified + /// Returns a yield if an alias is specified pub(crate) fn alias(&self) -> Option<&Idiom> { match self { Part::Graph(v) => v.alias.as_ref(), diff --git a/lib/src/sql/strand.rs b/lib/src/sql/strand.rs index 8a7b50e0..e74590b0 100644 --- a/lib/src/sql/strand.rs +++ b/lib/src/sql/strand.rs @@ -44,12 +44,15 @@ impl Deref for Strand { } impl Strand { + /// Get the underlying String slice pub fn as_str(&self) -> &str { self.0.as_str() } + /// Returns the underlying String pub fn as_string(self) -> String { self.0 } + /// Convert the Strand to a raw String pub fn to_raw(self) -> String { self.0 } diff --git a/lib/src/sql/thing.rs b/lib/src/sql/thing.rs index 111cf5e4..d57f06cc 100644 --- a/lib/src/sql/thing.rs +++ b/lib/src/sql/thing.rs @@ -44,6 +44,7 @@ impl From<(&str, &str)> for Thing { } impl Thing { + /// Convert the Thing to a raw String pub fn to_raw(&self) -> String { self.to_string() } diff --git a/lib/src/sql/uuid.rs b/lib/src/sql/uuid.rs index fd1dc88d..725de7c4 100644 --- a/lib/src/sql/uuid.rs +++ b/lib/src/sql/uuid.rs @@ -36,15 +36,19 @@ impl Deref for Uuid { } impl Uuid { + /// Generate a new V4 UUID pub fn new() -> Self { Self(uuid::Uuid::new_v4()) } + /// Generate a new V4 UUID pub fn new_v4() -> Self { Self(uuid::Uuid::new_v4()) } + /// Generate a new V7 UUID pub fn new_v7() -> Self { Self(uuid::Uuid::now_v7()) } + /// Convert the Uuid to a raw String pub fn to_raw(&self) -> String { self.0.to_string() }