ucsi/macros/
impl_unit_def.rs1#[macro_export]
28macro_rules! __impl_si_associated_unit_def {
29 (
30 alias $vis:vis mod $mod:ident;
31 $(
32 $(#[$attr:meta])*
33 unit $name:ident
34 based on $ty:ty {
35 $($key:ident: $val:expr),*
36 $(,)?
37 }
38 $(alias $($al:ident),+)?
39 $(conversion $block_tt:tt)?;
40 )+
41 ) => {
42 $(
43 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
44 $(#[$attr])*
45 pub struct $name;
46
47 impl $crate::core::units::associated::SiAssociatedUnit for $name {
48 type BaseUnit = $ty;
49 const DEF: $crate::core::units::associated::SiAssociatedUnitDefinition =
50 $crate::core::units::associated::SiAssociatedUnitDefinition {
51 $($key: $val),*
52 };
53 }
54
55 impl $crate::core::units::any::SiDefinedUnit for $name {
56 const DEF: ::core::option::Option<$crate::core::units::any::SiDefinedUnitDefinition> =
57 ::core::option::Option::Some($crate::core::units::any::SiDefinedUnitDefinition {
58 full_name: <$name as $crate::core::units::associated::SiAssociatedUnit>::DEF.full_name,
59 short_name: <$name as $crate::core::units::associated::SiAssociatedUnit>::DEF.short_name,
60 unit_symbol: <$name as $crate::core::units::associated::SiAssociatedUnit>::DEF.unit_symbol,
61 });
62 }
63
64 impl $crate::core::units::any::SiAnyUnit for $name {}
65
66 $($crate::__impl_unit_conversion! { $name $block_tt; })?
67 )+
68
69 $($(
70 $vis mod $mod {
71 #[allow(non_camel_case_types)]
72 $(pub type $al = super::$name;)+
73 }
74 )?)+
75 };
76}
77
78#[macro_export]
98macro_rules! __impl_si_exported_unit_def {
99 (
100 alias $vis:vis mod $mod:ident;
101 $(
102 $(#[$attr:meta])*
103 unit $name:ident based on $ty:ty {
104 $($key:ident: $val:expr),*
105 $(,)?
106 } $(alias $($al:ident),+ $(,)?)?;
107 )+
108 ) => {
109 $(
110 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
111 $(#[$attr])*
112 pub struct $name;
113
114 impl $crate::core::units::exported::SiExportedUnit for $name {
115 type BaseUnit = $ty;
116 const DEF: $crate::core::units::exported::SiExportedUnitDefinition =
117 $crate::core::units::exported::SiExportedUnitDefinition {
118 $($key: $val),*
119 };
120 }
121
122 impl $crate::core::units::any::SiDefinedUnit for $name {
123 const DEF: ::core::option::Option<$crate::core::units::any::SiDefinedUnitDefinition> =
124 ::core::option::Option::Some($crate::core::units::any::SiDefinedUnitDefinition {
125 full_name: <$name as $crate::core::units::exported::SiExportedUnit>::DEF.full_name,
126 short_name: <$name as $crate::core::units::exported::SiExportedUnit>::DEF.short_name,
127 unit_symbol: <$name as $crate::core::units::exported::SiExportedUnit>::DEF.unit_symbol,
128 });
129 }
130
131 impl $crate::core::units::any::SiOpsUnit for $name {
132 const UNIT_MAP: $crate::core::units::base::BaseUnitMap =
133 <$name as $crate::core::units::exported::SiExportedUnit>::BaseUnit::UNIT_MAP;
134 }
135
136 impl $crate::core::units::any::SiAnyUnit for $name {}
137 )+
138
139 $($(
140 $vis mod $mod {
141 #[allow(non_camel_case_types)]
142 $(pub type $al = super::$name;)+
143 }
144 )?)+
145 };
146}