]>
git.proxmox.com Git - rustc.git/blob - vendor/time-core/src/convert.rs
1 //! Conversion between units of time.
6 /// A trait for defining the ratio of two units of time.
8 /// This trait is used to implement the `per` method on the various structs.
10 /// The smallest unsigned integer type that can represent [`VALUE`](Self::VALUE).
13 /// The number of one unit of time in the other.
14 const VALUE
: Self::Output
;
18 /// Declare and implement `Per` for all relevant types. Identity implementations are automatic.
19 macro_rules
! impl_per
{
20 ($
($t
:ident ($
str:literal
) per
{$
(
21 $larger
:ident
: $output
:ty
= $value
:expr
23 #[doc = concat!("A unit of time representing exactly one ", $str, ".")]
24 #[derive(Debug, Clone, Copy)]
28 #[doc = concat!("Obtain the number of times `", stringify!($t), "` can fit into `T`.")]
29 #[doc = concat!("If `T` is smaller than `", stringify!($t), "`, the code will fail to")]
30 /// compile. The return type is the smallest unsigned integer type that can represent
35 #[doc = concat!(" - `", stringify!($t), "::per(", stringify!($t), ")` (returns `u8`)")]
36 $
(#[doc = concat!(" - `", stringify!($t), "::per(", stringify!($larger), ")` (returns `", stringify!($output), "`)")])*
37 pub const fn per
<T
>(_larger
: T
) -> <Self as Per
<T
>>::Output
52 $
(impl Per
<$larger
> for $t
{
53 type Output
= $output
;
55 const VALUE
: $output
= $value
;
61 Nanosecond ("nanosecond") per
{
62 Microsecond
: u16 = 1_000
63 Millisecond
: u32 = 1_000_000
64 Second
: u32 = 1_000_000_000
65 Minute
: u64 = 60_000_000_000
66 Hour
: u64 = 3_600_000_000_000
67 Day
: u64 = 86_400_000_000_000
68 Week
: u64 = 604_800_000_000_000
70 Microsecond ("microsecond") per
{
71 Millisecond
: u16 = 1_000
72 Second
: u32 = 1_000_000
73 Minute
: u32 = 60_000_000
74 Hour
: u32 = 3_600_000_000
75 Day
: u64 = 86_400_000_000
76 Week
: u64 = 604_800_000_000
78 Millisecond ("millisecond") per
{
83 Week
: u32 = 604_800_000
85 Second ("second") per
{
91 Minute ("minute") per
{