Make error sets explicit

This commit is contained in:
2022-01-10 16:45:04 -07:00
parent ed2445e623
commit b734196410
2 changed files with 11 additions and 13 deletions

View File

@ -227,14 +227,15 @@ pub fn Window(comptime TUserData: type) type {
reserved: u27 = 0,
};
pub fn open(title: [*:0]const u8, width: u32, height: u32, flags: OpenFlags) !Window(TUserData) {
const OpenError = error{OpenFailed};
pub fn open(title: [*:0]const u8, width: u32, height: u32, flags: OpenFlags) OpenError!Window(TUserData) {
const cwin: ?*c.mfb_window = c.mfb_open_ex(title, width, height, @bitCast(u32, flags));
if (cwin) |value| {
const win = Window(TUserData){ .cwin = value };
assert(@bitCast(usize, win) == @ptrToInt(win.cwin));
return win;
} else {
return error.ItBroke;
return OpenError.OpenFailed;
}
}
@ -367,12 +368,12 @@ test "set and get target FPS" {
pub const Timer = extern struct {
ctimer: *c.mfb_timer,
pub fn init() !Timer {
pub fn init() std.mem.Allocator.Error!Timer {
const ctimer: ?*c.mfb_timer = c.mfb_timer_create();
if (ctimer) |value| {
return Timer{ .ctimer = value };
} else {
return error.ItBroke;
return std.mem.Allocator.Error.OutOfMemory;
}
}