1
0
Fork 0
forked from wry/wry

fractional-scale: implement accurate rounding

This commit is contained in:
Julian Orth 2024-10-22 11:11:29 +02:00
parent cc426a0a4a
commit e2806a6337
5 changed files with 41 additions and 14 deletions

View file

@ -0,0 +1,28 @@
pub trait ArrayToTuple {
type Tuple;
fn to_tuple(self) -> Self::Tuple;
}
macro_rules! ignore {
($t:tt) => {
T
};
}
macro_rules! array_to_tuple {
($n:expr, $($field:ident,)*) => {
impl<T> ArrayToTuple for [T; $n] {
type Tuple = ($(ignore!($field),)*);
fn to_tuple(self) -> Self::Tuple {
let [$($field,)*] = self;
#[allow(clippy::allow_attributes)]
#[allow(clippy::unused_unit)]
($($field,)*)
}
}
};
}
array_to_tuple!(2, t1, t2,);