mod sealed { /// A trait for defining the ratio of two units of time. /// /// This trait is used to implement the `per` method on the various structs. pubtrait Per<T> { /// The smallest unsigned integer type that can represent [`VALUE`](Self::VALUE). type Output;
/// The number of one unit of time in the other. const VALUE: Self::Output;
}
}
/// Declare and implement `Per` for all relevant types. Identity implementations are automatic.
macro_rules! impl_per {
($($t:ident ($str:literal) per {$(
$larger:ident : $output:ty = $value:expr
)*})*) => {$( #[doc = concat!("A unit of time representing exactly one ", $str, ".")] #[derive(Debug, Clone, Copy)] pubstruct $t;
impl $t { #[doc = concat!("Obtain the number of times `", stringify!($t), "` can fit into `T`.")] #[doc = concat!("If `T` is smaller than `", stringify!($t), "`, the code will fail to")] /// compile. The return type is the smallest unsigned integer type that can represent /// the value. /// /// Valid calls: /// #[doc = concat!(" - `", stringify!($t), "::per(", stringify!($t), ")` (returns `u8`)")]
$(#[doc = concat!(" - `", stringify!($t), "::per(", stringify!($larger), ")` (returns `", stringify!($output), "`)")])* pubconstfn per<T>(_larger: T) -> <Selfas Per<T>>::Output where Self: Per<T>,
T: Copy,
{ Self::VALUE
}
}
impl Per<$t> for $t { type Output = u8;
const VALUE: u8 = 1;
}
$(impl Per<$larger> for $t { type Output = $output;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.