Expand description
This crate exports two macros, which are intended to replicate the functionality of Swift’s
guard expression with Option<T>
.
The guard!
macro was created to emulate the guard let
statement in Swift. This macro is only
really useful for moving values out of Option<T>
s into variables.
The ward!
macro, on the other hand, doesn’t force the creation of a variable, it only returns
the value that the guard!
variable would place into a variable. As such, it’s a more flexible
version of the guard!
macro; and probably also somewhat more Rustic.
Macros§
- guard
- Creates a variable with the contents of a
Option<T>
’sSome(T)
, otherwise it returns early from the function. Can alternatively have anelse
branch, or an alternative “early return” statement, likebreak
orcontinue
for loops, e.g. - ward
- Returns the contents of a
Option<T>
’sSome(T)
, otherwise it returns early from the function. Can alternatively have anelse
branch, or an alternative “early return” statement, likebreak
orcontinue
for loops, e.g.