package tcom import "base:intrinsics" // // Calls the given proc and returns the given errval if the proc returns ok = false. // ok_to_err :: proc(p: proc(arg: $A) -> ($R, bool), a: A, errval: $E) -> (ret: R, err: E) { // ok: bool // ret, ok = p(a) // if !ok { err = errval } // return // } // // Attempts to unwrap a variant of v and returns the given errval if the unwrap fails. // unwrap_variant :: proc(v: $V, $T: typeid, errval: $E) -> (ret: T, err: E) { // ok: bool // ret, ok = v.(T) // if !ok { err = errval } // return // } panic_invalid_enum :: proc(e: $T) -> ! where intrinsics.type_is_enum(T) { fmt.panicf("enum of type {} has invalid value %i", typeid_of(T), e) }