Skip to content

Commit

Permalink
Implement TypeInfo for Duration (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Jun 21, 2023
1 parent 152ef28 commit 1d5ce77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::prelude::{
},
string::String,
sync::Arc,
time::Duration,
vec::Vec,
};

Expand Down Expand Up @@ -161,6 +162,24 @@ impl_for_non_zero!(
NonZeroU128: u128
);

impl TypeInfo for Duration {
type Identity = Self;

fn type_info() -> Type {
Type::builder().path(Path::prelude("Duration")).composite(
Fields::unnamed()
.field(|f| {
// Seconds
f.ty::<u64>().type_name("u64")
})
.field(|f| {
// Nanoseconds
f.ty::<u32>().type_name("u32")
}),
)
}
}

impl<T> TypeInfo for Vec<T>
where
T: TypeInfo + 'static,
Expand Down
2 changes: 2 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cfg_if! {
ops,
string,
sync,
time,
vec,
};
} else {
Expand All @@ -60,6 +61,7 @@ cfg_if! {
mem,
num,
ops,
time,
};
}
}

0 comments on commit 1d5ce77

Please sign in to comment.