Skip to content

Commit

Permalink
Add docstring + nits
Browse files Browse the repository at this point in the history
  • Loading branch information
eelanagaraj committed Feb 5, 2024
1 parent 7ee3d98 commit 6d35a36
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cwt/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum Key {
Text(String),
Integer(i128),
}

impl From<Key> for Value {
fn from(key: Key) -> Value {
match key {
Expand Down Expand Up @@ -50,6 +51,7 @@ pub enum NumericDate {
IntegerSeconds(i128),
FractionalSeconds(f64),
}

impl From<NumericDate> for Value {
fn from(value: NumericDate) -> Self {
match value {
Expand Down Expand Up @@ -98,9 +100,14 @@ impl TryFrom<NumericDate> for OffsetDateTime {
}
}
}

impl TryFrom<OffsetDateTime> for NumericDate {
type Error = Error;

/// To IntegerSeconds: lossless conversion.
/// To FractionalSeconds: computes the f64 from the seconds
/// and then converts nanoseconds into a decimal.
/// May return an error if too many nanoseconds are returned by OffsetDateTime,
/// but that should not happen according to OffsetDateTime's docs.
fn try_from(value: OffsetDateTime) -> Result<Self, Self::Error> {
match value.nanosecond() {
0 => Ok(NumericDate::IntegerSeconds(value.unix_timestamp().into())),
Expand Down

0 comments on commit 6d35a36

Please sign in to comment.