-
-
Save durka/5846f4b2ec7c09446562822d08af6b42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Try downcasting an Any to several types, performing the same or different actions if one of the | |
| /// types matches, otherwise do a fallback | |
| /// | |
| /// Syntax is similar to `match`, except the types are separated by commas and the _ case comes | |
| /// first (TODO fix this) | |
| #[macro_export] | |
| macro_rules! downcast { | |
| ($any:ident { _ => $code:expr, $($($ts:ty),+ => $codes:expr),* }) => { | |
| $( | |
| $( | |
| if let Some($any) = $any.downcast_ref::<$ts>() { | |
| $codes | |
| } | |
| )else+ | |
| )else* | |
| else { $code } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment