Add some additional code comments

This commit is contained in:
Tobie Morgan Hitchcock 2022-10-19 10:55:19 +01:00
parent 73bf56810e
commit ad6ee5b42d
9 changed files with 21 additions and 7 deletions

View file

@ -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)
}

View file

@ -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;

View file

@ -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()
}

View file

@ -83,9 +83,11 @@ impl From<Vec<Value>> 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(),

View file

@ -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()
}

View file

@ -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(),

View file

@ -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
}

View file

@ -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()
}

View file

@ -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()
}