|
11 | 11 | /// The current implementation checks [`Gd::try_cast()`][crate::obj::Gd::try_cast] linearly with the number of branches.
|
12 | 12 | /// This may change in the future.
|
13 | 13 | ///
|
14 |
| -/// Only requires a fallback branch if the type of the expression is different than `()`, and in such case it's required 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), and the arm needs to return a value of that type. 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. |
17 | 20 | ///
|
18 | 21 | /// # Example
|
19 | 22 | /// ```no_run
|
|
51 | 54 | /// original => 0,
|
52 | 55 | /// // Can also be used with mut:
|
53 | 56 | /// // mut original => 0,
|
54 |
| -/// // It can't be left out because the expression has a type. |
55 |
| -/// // Otherwise, we could've skipped this branch. |
| 57 | +/// // If the match arms have type (), we can also omit the fallback branch. |
56 | 58 | /// };
|
57 | 59 | ///
|
58 | 60 | /// // event_type is now 0, 1, 2, or 3
|
@@ -109,7 +111,8 @@ macro_rules! match_class_muncher {
|
109 | 111 | $block
|
110 | 112 | }};
|
111 | 113 |
|
112 |
| - // _ => { ... } or nothing, if there is no need for a return value. |
| 114 | + // _ => { ... } |
| 115 | + // or nothing, if fallback is absent and overall expression being (). |
113 | 116 | ($subject:ident, $(_ => $block:expr $(,)?)?) => {{
|
114 | 117 | $($block)?
|
115 | 118 | }};
|
|
0 commit comments