raiguard/tcom

git clone https://git.raiguard.me/raiguard/tcom

Caleb HeuerNo idea what I was working on...7992681

trunk
690 B23 linesraw
1package tcom
2
3import "base:intrinsics"
4
5// // Calls the given proc and returns the given errval if the proc returns ok = false.
6// ok_to_err :: proc(p: proc(arg: $A) -> ($R, bool), a: A, errval: $E) -> (ret: R, err: E) {
7// 	ok: bool
8// 	ret, ok = p(a)
9// 	if !ok { err = errval }
10// 	return
11// }
12
13// // Attempts to unwrap a variant of v and returns the given errval if the unwrap fails.
14// unwrap_variant :: proc(v: $V, $T: typeid, errval: $E) -> (ret: T, err: E) {
15// 	ok: bool
16// 	ret, ok = v.(T)
17// 	if !ok { err = errval }
18// 	return
19// }
20
21panic_invalid_enum :: proc(e: $T) -> ! where intrinsics.type_is_enum(T) {
22	fmt.panicf("enum of type {} has invalid value %i", typeid_of(T), e)
23}