aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-05-14 14:07:05 +0200
committerHampusM <hampus@hampusmat.com>2023-05-14 14:07:05 +0200
commit530af717e7b7efda996fe28a24512d3d662d708e (patch)
treeb90fd8735b0d647c3209568fa2ba0fb7f6ade5c8 /src/util.rs
parent9588367284139266b55936d93428355cfa6de906 (diff)
refactor: improve definition of MaybeStatic
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/util.rs b/src/util.rs
index 5c9ffb8..d96c4f4 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,13 +1,38 @@
macro_rules! trait_alias {
(
$(#[$attr: meta])*
- $visibility: vis $name: ident$(<$($type_param: ident),*>)?$(: $first_bound: tt $(+ $bound: tt)*)?;
+ $visibility: vis $name: ident$(<$($type_param: ident),*>)?
+ $(: $first_bound: tt $(+ $bound: tt)*)?;
) => {
$(#[$attr])*
$visibility trait $name $(<$($type_param),*>)? $(: $first_bound $(+ $bound)*)? {}
- impl<T: $($first_bound $(+ $bound)*)?, $($($type_param),*)?> $name$(<$($type_param),*>)? for T {}
+ impl<
+ T: $($first_bound $(+ $bound)*)?,
+ $($($type_param),*)?
+ > $name$(<$($type_param),*>)? for T {}
};
+
+ // Rule where the trait bounds will only be applied if the specified feature is enabled
+ (
+ bounds_when_feature = $bounds_feature: literal,
+ $(#[$attr: meta])*
+ $visibility: vis $name: ident$(<$($type_param: ident),*>)?
+ $(: $first_bound: tt $(+ $bound: tt)*)?;
+ ) => {
+ #[cfg(feature = $bounds_feature)]
+ trait_alias! {
+ $(#[$attr])*
+ $visibility $name$(<$($type_param),*>)?
+ $(: $first_bound $(+ $bound)*)?;
+ }
+
+ #[cfg(not(feature = $bounds_feature))]
+ trait_alias! {
+ $(#[$attr])*
+ $visibility $name$(<$($type_param),*>)?;
+ }
+ }
}
macro_rules! feature_alternate {