1111/// The current implementation checks [`Gd::try_cast()`][crate::obj::Gd::try_cast] linearly with the number of branches.
1212/// This may change in the future.
1313///
14- /// Requires a fallback branch, even if all direct known classes are handled. The reason for this is that there may be other subclasses which
15- /// are not statically known by godot-rust (e.g. from a script or GDExtension). The fallback branch can either be `_` (discard object), or
16- /// `variable` to access the original object inside the fallback arm.
14+ /// When none of the listed classes match, a _fallback branch_ acts as a catch-all and allows to retrieve the original `Gd` pointer.
15+ /// If the type of the `match_class!` expression is `()`, you can omit the fallback branch. For all other types, it is required, even if all
16+ /// direct subclasses are handled. The reason for this is that there may be other subclasses which are not statically known by godot-rust
17+ /// (e.g. from a script or GDExtension).
18+ ///
19+ /// The fallback branch can either be `_` (discard object), or `variable` to access the original object inside the fallback arm.
1720///
1821/// # Example
1922/// ```no_run
5154/// original => 0,
5255/// // Can also be used with mut:
5356/// // mut original => 0,
57+ /// // If the match arms have type (), we can also omit the fallback branch.
5458/// };
5559///
5660/// // event_type is now 0, 1, 2, or 3
@@ -75,14 +79,6 @@ macro_rules! match_class {
7579#[ doc( hidden) ]
7680#[ macro_export]
7781macro_rules! match_class_muncher {
78- /*
79- // If we want to support `variable @ _ => { ... }` syntax, use this branch first (to not match `_` as type).
80- ($subject:ident, $var:ident @ _ => $block:expr $(,)?) => {{
81- let $var = $subject;
82- $block
83- }};
84- */
85-
8682 // mut variable @ Class => { ... }.
8783 ( $subject: ident, mut $var: ident @ $Ty: ty => $block: expr, $( $rest: tt) * ) => { {
8884 match $subject. try_cast:: <$Ty>( ) {
@@ -115,8 +111,9 @@ macro_rules! match_class_muncher {
115111 $block
116112 } } ;
117113
118- // _ => { ... }.
119- ( $subject: ident, _ => $block: expr $( , ) ?) => { {
120- $block
114+ // _ => { ... }
115+ // or nothing, if fallback is absent and overall expression being ().
116+ ( $subject: ident, $( _ => $block: expr $( , ) ?) ?) => { {
117+ $( $block) ?
121118 } } ;
122119}
0 commit comments