Diffstat (limited to 'src/any.rs')
-rw-r--r--src/any.rs44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/any.rs b/src/any.rs
index 028f610..5c6a262 100644
--- a/src/any.rs
+++ b/src/any.rs
@@ -244,12 +244,18 @@ impl<'b, 'ctx: 'b> dyn AnyTrait<'ctx> + Send + Sync + 'b {
macro_rules! any_trait {
{
impl[$lt:lifetime $($generic:tt)*] $name:ty = [$($protocol:ty),* $(,)?]
+ ref {
+ let ($if_this:ident, $if_id:ident);
+ $($if_fallback:tt)*
+ }
else ref {
- let ($this:ident, $id:ident);
$($fallback:tt)*
}
+ mut {
+ let ($if_mut_this:ident, $if_mut_id:ident);
+ $($if_mut_fallback:tt)*
+ }
else mut {
- let ($mut_this:ident, $mut_id:ident);
$($mut_fallback:tt)*
}
$(where $($bound:tt)*)?
@@ -269,14 +275,19 @@ macro_rules! any_trait {
where
$lt: '__
{
+ let ($if_this, $if_id) = (self, id);
+
+ {
+ $($if_fallback)*
+ }
+
// This match should be optimized well by llvm.
- match id {
+ match $if_id {
$(id if id == $crate::any::TypeNameId::of::<$protocol>()
=> ::core::option::Option::Some($crate::any::AnyTraitObject::<'__, $lt, _>::new::<
$crate::any::TypeName::T<'__, $lt, $protocol>
- >(self as _)),)*
- $id => {
- let $this = self;
+ >($if_this as _)),)*
+ _ => {
$($fallback)*
}
}
@@ -290,14 +301,19 @@ macro_rules! any_trait {
where
$lt: '__
{
+ let ($if_mut_this, $if_mut_id) = (self, id);
+
+ {
+ $($if_mut_fallback)*
+ }
+
// This match should be optimized well by llvm.
- match id {
+ match $if_mut_id {
$(id if id == $crate::any::TypeNameId::of::<$protocol>()
=> ::core::option::Option::Some($crate::any::AnyTraitObject::<'__, $lt, _>::new::<
$crate::any::TypeName::T<'__, $lt, $protocol>
- >(self as _)),)*
- $mut_id => {
- let $mut_this = self;
+ >($if_mut_this as _)),)*
+ _ => {
$($mut_fallback)*
}
}
@@ -310,13 +326,15 @@ macro_rules! any_trait {
} => {
$crate::any::any_trait! {
impl[$lt $($generic)*] $name = [$($protocol),*]
- else ref {
- // Always answer no in the fallback branch if no fallback was given.
+ ref {
let (_this, _id);
+ } else ref {
+ // Always answer no in the fallback branch if no fallback was given.
::core::option::Option::None
+ } mut {
+ let (_this, _id);
} else mut {
// Always answer no in the fallback branch if no fallback was given.
- let (_this, _id);
::core::option::Option::None
} $(where $($bound)*)?
}