std1.0.0-beta-7 SafeC docs

Module result

#include <std/result.h> source

Result<T,E>: a value or an error, stored inline

struct Result<int, long long> r = std::Result::new_ok(42);   // E taken from the target type
if (r.ok()) { int v = r.get_ok().default(0); }
struct Result<int, long long> e = std::Result::new_err(7LL);
match (e.get_err()) { case some(code): ...; case null: ... }

No heap allocation: both slots live in the struct and only the one named by 'is_ok' is meaningful. When T or E owns something (a Drop type), so does the Result: drop() drops whichever slot is live, and unwrap_or() consumes it, as do unwrap() / unwrap_err() (which panic on the other kind).

Structs

Result