Error Handling » Monadic Interfaces module

Cnx provides some uniform interfaces for some of its monad-like types

Defines

#define if_let(var, self)
if_let(var, self) provides an abstraction to conditionally retrieve a value

Define documentation

#define if_let(var, self)

if_let(var, self) provides an abstraction to conditionally retrieve a value

Parameters
var - The name for the variable the value held by self will be extracted to
self - The CnxOption(T), CnxResult(T), or other compatible type potentially holding a value

if_let(var, self) provides an abstraction to conditionally retrieve a value from a conditional wrapper type, like CnxOption(T) or CnxResult(T), and then perform some operations with that value. Example:

CnxOption(u32) do_thing(void);

void example(void) {
    let_mut maybe_thing = do_thing();
    if_let(thing, maybe_thing) {
        // do something with thing...
    }
    else {
        // handle maybe_thing being `None(T)`
    }
}