From ef7ada052c1103951b556e450641e418fb9f52b0 Mon Sep 17 00:00:00 2001 From: InKryption Date: Mon, 22 Nov 2021 00:34:38 +0100 Subject: [PATCH] glfw: Revert error denormalization --- glfw/src/Cursor.zig | 8 +-- glfw/src/Joystick.zig | 36 +++++------ glfw/src/Monitor.zig | 44 ++++++------- glfw/src/Window.zig | 136 ++++++++++++++++++++--------------------- glfw/src/clipboard.zig | 8 +-- glfw/src/key.zig | 8 +-- glfw/src/main.zig | 24 ++++---- glfw/src/opengl.zig | 12 ++-- glfw/src/time.zig | 4 +- glfw/src/vulkan.zig | 12 ++-- 10 files changed, 146 insertions(+), 146 deletions(-) diff --git a/glfw/src/Cursor.zig b/glfw/src/Cursor.zig index ed089aa6..9334d8ef 100644 --- a/glfw/src/Cursor.zig +++ b/glfw/src/Cursor.zig @@ -60,12 +60,12 @@ pub const Shape = enum(isize) { /// @thread_safety This function must only be called from the main thread. /// /// see also: cursor_object, glfw.Cursor.destroy, glfw.Cursor.createStandard -pub inline fn create(image: Image, xhot: isize, yhot: isize) error{ PlatformError }!Cursor { +pub inline fn create(image: Image, xhot: isize, yhot: isize) Error!Cursor { internal_debug.assertInitialized(); const img = image.toC(); const cursor = c.glfwCreateCursor(&img, @intCast(c_int, xhot), @intCast(c_int, yhot)); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return Cursor{ .ptr = cursor.? }; @@ -80,13 +80,13 @@ pub inline fn create(image: Image, xhot: isize, yhot: isize) error{ PlatformErro /// @thread_safety This function must only be called from the main thread. /// /// see also: cursor_object, glfwCreateCursor -pub inline fn createStandard(shape: Shape) error{ InvalidEnum, PlatformError }!Cursor { +pub inline fn createStandard(shape: Shape) Error!Cursor { internal_debug.assertInitialized(); const cursor = c.glfwCreateStandardCursor(@intCast(c_int, @enumToInt(shape))); getError() catch |err| return switch (err) { // TODO: should be impossible given that only the values in 'Shape' are available, unless the user explicitly gives us a bad value via casting Error.InvalidEnum => unreachable, - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return Cursor{ .ptr = cursor.? }; diff --git a/glfw/src/Joystick.zig b/glfw/src/Joystick.zig index 21e06f98..1c01570e 100644 --- a/glfw/src/Joystick.zig +++ b/glfw/src/Joystick.zig @@ -86,13 +86,13 @@ const GamepadState = extern struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: joystick -pub inline fn present(self: Joystick) error{ InvalidEnum, PlatformError }!bool { +pub inline fn present(self: Joystick) Error!bool { internal_debug.assertInitialized(); const is_present = c.glfwJoystickPresent(self.jid); getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, PlatformError }, err), + => err, else => unreachable, }; return is_present == c.GLFW_TRUE; @@ -118,14 +118,14 @@ pub inline fn present(self: Joystick) error{ InvalidEnum, PlatformError }!bool { /// /// see also: joystick_axis /// Replaces `glfwGetJoystickPos`. -pub inline fn getAxes(self: Joystick) error{ InvalidEnum, PlatformError }!?[]const f32 { +pub inline fn getAxes(self: Joystick) Error!?[]const f32 { internal_debug.assertInitialized(); var count: c_int = undefined; const axes = c.glfwGetJoystickAxes(self.jid, &count); getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, PlatformError }, err), + => err, else => unreachable, }; if (axes == null) return null; @@ -156,14 +156,14 @@ pub inline fn getAxes(self: Joystick) error{ InvalidEnum, PlatformError }!?[]con /// @thread_safety This function must only be called from the main thread. /// /// see also: joystick_button -pub inline fn getButtons(self: Joystick) error{ InvalidEnum, PlatformError }!?[]const u8 { +pub inline fn getButtons(self: Joystick) Error!?[]const u8 { internal_debug.assertInitialized(); var count: c_int = undefined; const buttons = c.glfwGetJoystickButtons(self.jid, &count); getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, PlatformError }, err), + => err, else => unreachable, }; if (buttons == null) return null; @@ -210,14 +210,14 @@ pub inline fn getButtons(self: Joystick) error{ InvalidEnum, PlatformError }!?[] /// @thread_safety This function must only be called from the main thread. /// /// see also: joystick_hat -pub inline fn getHats(self: Joystick) error{ InvalidEnum, PlatformError }!?[]const Hat { +pub inline fn getHats(self: Joystick) Error!?[]const Hat { internal_debug.assertInitialized(); var count: c_int = undefined; const hats = c.glfwGetJoystickHats(self.jid, &count); getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, PlatformError }, err), + => err, else => unreachable, }; if (hats == null) return null; @@ -244,13 +244,13 @@ pub inline fn getHats(self: Joystick) error{ InvalidEnum, PlatformError }!?[]con /// @thread_safety This function must only be called from the main thread. /// /// see also: joystick_name -pub inline fn getName(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]const u8 { +pub inline fn getName(self: Joystick) Error!?[:0]const u8 { internal_debug.assertInitialized(); const name_opt = c.glfwGetJoystickName(self.jid); getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, PlatformError }, err), + => err, else => unreachable, }; return if (name_opt) |name| @@ -286,13 +286,13 @@ pub inline fn getName(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]c /// @thread_safety This function must only be called from the main thread. /// /// see also: gamepad -pub inline fn getGUID(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]const u8 { +pub inline fn getGUID(self: Joystick) Error!?[:0]const u8 { internal_debug.assertInitialized(); const guid_opt = c.glfwGetJoystickGUID(self.jid); getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, PlatformError }, err), + => err, else => unreachable, }; return if (guid_opt) |guid| @@ -404,11 +404,11 @@ pub inline fn setCallback(callback: ?fn (joystick: Joystick, event: Event) void) /// /// /// @ingroup input -pub inline fn updateGamepadMappings(gamepad_mappings: [*:0]const u8) error{ InvalidValue }!void { +pub inline fn updateGamepadMappings(gamepad_mappings: [*:0]const u8) Error!void { internal_debug.assertInitialized(); _ = c.glfwUpdateGamepadMappings(gamepad_mappings); getError() catch |err| return switch (err) { - Error.InvalidValue => @errSetCast(error{ InvalidValue }, err), + Error.InvalidValue => err, else => unreachable, }; } @@ -462,11 +462,11 @@ pub inline fn isGamepad(self: Joystick) bool { /// see also: gamepad, glfw.Joystick.isGamepad // TODO: Consider this; GLFW documentation for this function doesn't list any errors, // but source code in 'init.c' only appears to return 'GLFW_INVALID_ENUM' and 'GLFW_NOT_INITIALIZED' on error. -pub inline fn getGamepadName(self: Joystick) error{ InvalidEnum }!?[:0]const u8 { +pub inline fn getGamepadName(self: Joystick) Error!?[:0]const u8 { internal_debug.assertInitialized(); const name_opt = c.glfwGetGamepadName(self.jid); getError() catch |err| return switch (err) { - Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err), + Error.InvalidEnum => err, else => unreachable, }; return if (name_opt) |name| @@ -499,12 +499,12 @@ pub inline fn getGamepadName(self: Joystick) error{ InvalidEnum }!?[:0]const u8 /// @thread_safety This function must only be called from the main thread. /// /// see also: gamepad, glfw.UpdateGamepadMappings, glfw.Joystick.isGamepad -pub inline fn getGamepadState(self: Joystick) error{ InvalidEnum }!?GamepadState { +pub inline fn getGamepadState(self: Joystick) Error!?GamepadState { internal_debug.assertInitialized(); var state: GamepadState = undefined; const success = c.glfwGetGamepadState(self.jid, @ptrCast(*c.GLFWgamepadstate, &state)); getError() catch |err| return switch (err) { - Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err), + Error.InvalidEnum => err, else => unreachable, }; return if (success == c.GLFW_TRUE) state else null; diff --git a/glfw/src/Monitor.zig b/glfw/src/Monitor.zig index dfc17eaf..2021d6f0 100644 --- a/glfw/src/Monitor.zig +++ b/glfw/src/Monitor.zig @@ -32,13 +32,13 @@ const Pos = struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: monitor_properties -pub inline fn getPos(self: Monitor) error{ PlatformError }!Pos { +pub inline fn getPos(self: Monitor) Error!Pos { internal_debug.assertInitialized(); var xpos: c_int = 0; var ypos: c_int = 0; c.glfwGetMonitorPos(self.handle, &xpos, &ypos); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return Pos{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos) }; @@ -64,7 +64,7 @@ const Workarea = struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: monitor_workarea -pub inline fn getWorkarea(self: Monitor) error{ PlatformError }!Workarea { +pub inline fn getWorkarea(self: Monitor) Error!Workarea { internal_debug.assertInitialized(); var xpos: c_int = 0; var ypos: c_int = 0; @@ -72,7 +72,7 @@ pub inline fn getWorkarea(self: Monitor) error{ PlatformError }!Workarea { var height: c_int = 0; c.glfwGetMonitorWorkarea(self.handle, &xpos, &ypos, &width, &height); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return Workarea{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos), .width = @intCast(usize, width), .height = @intCast(usize, height) }; @@ -99,7 +99,7 @@ const PhysicalSize = struct { /// /// see also: monitor_properties // TODO: Remove error stub -pub inline fn getPhysicalSize(self: Monitor) error{}!PhysicalSize { +pub inline fn getPhysicalSize(self: Monitor) Error!PhysicalSize { internal_debug.assertInitialized(); var width_mm: c_int = 0; var height_mm: c_int = 0; @@ -131,13 +131,13 @@ const ContentScale = struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: monitor_scale, glfw.Window.getContentScale -pub inline fn getContentScale(self: Monitor) error{ PlatformError }!ContentScale { +pub inline fn getContentScale(self: Monitor) Error!ContentScale { internal_debug.assertInitialized(); var x_scale: f32 = 0; var y_scale: f32 = 0; c.glfwGetMonitorContentScale(self.handle, &x_scale, &y_scale); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return ContentScale{ .x_scale = @floatCast(f32, x_scale), .y_scale = @floatCast(f32, y_scale) }; @@ -158,7 +158,7 @@ pub inline fn getContentScale(self: Monitor) error{ PlatformError }!ContentScale /// /// see also: monitor_properties // TODO: Remove error stub -pub inline fn getName(self: Monitor) error{}![*:0]const u8 { +pub inline fn getName(self: Monitor) Error![*:0]const u8 { internal_debug.assertInitialized(); const name = c.glfwGetMonitorName(self.handle); getError() catch unreachable; @@ -179,7 +179,7 @@ pub inline fn getName(self: Monitor) error{}![*:0]const u8 { /// /// see also: monitor_userptr, glfw.Monitor.getUserPointer // TODO: Remove error stub -pub inline fn setUserPointer(self: Monitor, comptime T: type, ptr: *T) error{}!void { +pub inline fn setUserPointer(self: Monitor, comptime T: type, ptr: *T) Error!void { internal_debug.assertInitialized(); c.glfwSetMonitorUserPointer(self.handle, ptr); getError() catch unreachable; @@ -198,7 +198,7 @@ pub inline fn setUserPointer(self: Monitor, comptime T: type, ptr: *T) error{}!v /// /// see also: monitor_userptr, glfw.Monitor.setUserPointer // TODO: Remove error stub -pub inline fn getUserPointer(self: Monitor, comptime T: type) error{}!?*T { +pub inline fn getUserPointer(self: Monitor, comptime T: type) Error!?*T { internal_debug.assertInitialized(); const ptr = c.glfwGetMonitorUserPointer(self.handle); getError() catch unreachable; @@ -219,12 +219,12 @@ pub inline fn getUserPointer(self: Monitor, comptime T: type) error{}!?*T { /// @thread_safety This function must only be called from the main thread. /// /// see also: monitor_modes, glfw.Monitor.getVideoMode -pub inline fn getVideoModes(self: Monitor, allocator: *mem.Allocator) (mem.Allocator.Error || error{ PlatformError })![]VideoMode { +pub inline fn getVideoModes(self: Monitor, allocator: *mem.Allocator) Error![]VideoMode { internal_debug.assertInitialized(); var count: c_int = 0; const modes = c.glfwGetVideoModes(self.handle, &count); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; @@ -247,11 +247,11 @@ pub inline fn getVideoModes(self: Monitor, allocator: *mem.Allocator) (mem.Alloc /// @thread_safety This function must only be called from the main thread. /// /// see also: monitor_modes, glfw.Monitor.getVideoModes -pub inline fn getVideoMode(self: Monitor) error{ PlatformError }!VideoMode { +pub inline fn getVideoMode(self: Monitor) Error!VideoMode { internal_debug.assertInitialized(); const mode = c.glfwGetVideoMode(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return VideoMode{ .handle = mode.?.* }; @@ -276,14 +276,14 @@ pub inline fn getVideoMode(self: Monitor) error{ PlatformError }!VideoMode { /// @thread_safety This function must only be called from the main thread. /// /// see also: monitor_gamma -pub inline fn setGamma(self: Monitor, gamma: f32) error{ InvalidValue, PlatformError }!void { +pub inline fn setGamma(self: Monitor, gamma: f32) Error!void { internal_debug.assertInitialized(); c.glfwSetGamma(self.handle, gamma); getError() catch |err| return switch (err) { // TODO: Consider whether to assert that 'gamma' is a valid value instead of leaving it to GLFW's error handling. Error.InvalidValue, Error.PlatformError, - => @errSetCast(error{ InvalidValue, PlatformError }, err), + => err, else => unreachable, }; } @@ -303,11 +303,11 @@ pub inline fn setGamma(self: Monitor, gamma: f32) error{ InvalidValue, PlatformE /// @thread_safety This function must only be called from the main thread. /// /// see also: monitor_gamma -pub inline fn getGammaRamp(self: Monitor) error{ PlatformError }!GammaRamp { +pub inline fn getGammaRamp(self: Monitor) Error!GammaRamp { internal_debug.assertInitialized(); const ramp = c.glfwGetGammaRamp(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return GammaRamp.fromC(ramp.*); @@ -338,11 +338,11 @@ pub inline fn getGammaRamp(self: Monitor) error{ PlatformError }!GammaRamp { /// @thread_safety This function must only be called from the main thread. /// /// see also: monitor_gamma -pub inline fn setGammaRamp(self: Monitor, ramp: GammaRamp) error{ PlatformError }!void { +pub inline fn setGammaRamp(self: Monitor, ramp: GammaRamp) Error!void { internal_debug.assertInitialized(); c.glfwSetGammaRamp(self.handle, &ramp.toC()); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -383,7 +383,7 @@ pub inline fn getAll(allocator: *mem.Allocator) (mem.Allocator.Error)![]Monitor /// /// see also: monitor_monitors, glfw.monitors.getAll // TODO: Remove error stub -pub inline fn getPrimary() error{}!?Monitor { +pub inline fn getPrimary() Error!?Monitor { internal_debug.assertInitialized(); const handle = c.glfwGetPrimaryMonitor(); getError() catch unreachable; @@ -427,7 +427,7 @@ pub const Event = enum(c_int) { /// /// see also: monitor_event // TODO: Remove error stub -pub inline fn setCallback(comptime Data: type, data: *Data, f: ?*const fn (monitor: Monitor, event: Event, data: *Data) void) error{}!void { +pub inline fn setCallback(comptime Data: type, data: *Data, f: ?*const fn (monitor: Monitor, event: Event, data: *Data) void) Error!void { internal_debug.assertInitialized(); if (f) |new_callback| { callback_fn_ptr = @ptrToInt(new_callback); diff --git a/glfw/src/Window.zig b/glfw/src/Window.zig index 2b72abe6..4d5a15fb 100644 --- a/glfw/src/Window.zig +++ b/glfw/src/Window.zig @@ -73,7 +73,7 @@ pub const InternalUserPointer = struct { /// /// see also: window_hints, glfw.Window.hint, glfw.Window.hintString // TODO: Remove error stub -inline fn defaultHints() error{}!void { +inline fn defaultHints() Error!void { internal_debug.assertInitialized(); c.glfwDefaultWindowHints(); getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible @@ -259,7 +259,7 @@ pub const Hints = struct { }; // TODO: Remove error stub - fn set(hints: Hints) error{}!void { + fn set(hints: Hints) Error!void { internal_debug.assertInitialized(); inline for (comptime std.meta.fieldNames(Hint)) |field_name| { const hint_tag = @enumToInt(@field(Hint, field_name)); @@ -483,7 +483,7 @@ pub inline fn shouldClose(self: Window) bool { /// /// see also: window_close // TODO: Remove error stub -pub inline fn setShouldClose(self: Window, value: bool) error{}!void { +pub inline fn setShouldClose(self: Window, value: bool) Error!void { internal_debug.assertInitialized(); const boolean = if (value) c.GLFW_TRUE else c.GLFW_FALSE; c.glfwSetWindowShouldClose(self.handle, boolean); @@ -501,11 +501,11 @@ pub inline fn setShouldClose(self: Window, value: bool) error{}!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_title -pub inline fn setTitle(self: Window, title: [*:0]const u8) error{ PlatformError }!void { +pub inline fn setTitle(self: Window, title: [*:0]const u8) Error!void { internal_debug.assertInitialized(); c.glfwSetWindowTitle(self.handle, title); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -538,7 +538,7 @@ pub inline fn setTitle(self: Window, title: [*:0]const u8) error{ PlatformError /// @thread_safety This function must only be called from the main thread. /// /// see also: window_icon -pub inline fn setIcon(self: Window, allocator: *mem.Allocator, images: ?[]Image) (mem.Allocator.Error || error{ PlatformError })!void { +pub inline fn setIcon(self: Window, allocator: *mem.Allocator, images: ?[]Image) Error!void { internal_debug.assertInitialized(); if (images) |im| { const tmp = try allocator.alloc(c.GLFWimage, im.len); @@ -547,7 +547,7 @@ pub inline fn setIcon(self: Window, allocator: *mem.Allocator, images: ?[]Image) c.glfwSetWindowIcon(self.handle, @intCast(c_int, im.len), &tmp[0]); } else c.glfwSetWindowIcon(self.handle, 0, null); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -570,13 +570,13 @@ pub const Pos = struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_pos glfw.Window.setPos -pub inline fn getPos(self: Window) error{ PlatformError }!Pos { +pub inline fn getPos(self: Window) Error!Pos { internal_debug.assertInitialized(); var x: c_int = 0; var y: c_int = 0; c.glfwGetWindowPos(self.handle, &x, &y); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return Pos{ .x = @intCast(usize, x), .y = @intCast(usize, y) }; @@ -602,11 +602,11 @@ pub inline fn getPos(self: Window) error{ PlatformError }!Pos { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_pos, glfw.Window.getPos -pub inline fn setPos(self: Window, pos: Pos) error{ PlatformError }!void { +pub inline fn setPos(self: Window, pos: Pos) Error!void { internal_debug.assertInitialized(); c.glfwSetWindowPos(self.handle, @intCast(c_int, pos.x), @intCast(c_int, pos.y)); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -627,13 +627,13 @@ pub const Size = struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_size, glfw.Window.setSize -pub inline fn getSize(self: Window) error{ PlatformError }!Size { +pub inline fn getSize(self: Window) Error!Size { internal_debug.assertInitialized(); var width: c_int = 0; var height: c_int = 0; c.glfwGetWindowSize(self.handle, &width, &height); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) }; @@ -661,11 +661,11 @@ pub inline fn getSize(self: Window) error{ PlatformError }!Size { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_size, glfw.Window.getSize, glfw.Window.SetMonitor -pub inline fn setSize(self: Window, size: Size) error{ PlatformError }!void { +pub inline fn setSize(self: Window, size: Size) Error!void { internal_debug.assertInitialized(); c.glfwSetWindowSize(self.handle, @intCast(c_int, size.width), @intCast(c_int, size.height)); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -691,7 +691,7 @@ pub inline fn setSize(self: Window, size: Size) error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_sizelimits, glfw.Window.setAspectRatio -pub inline fn setSizeLimits(self: Window, min: Size, max: Size) error{ InvalidValue, PlatformError }!void { +pub inline fn setSizeLimits(self: Window, min: Size, max: Size) Error!void { internal_debug.assertInitialized(); c.glfwSetWindowSizeLimits( self.handle, @@ -703,7 +703,7 @@ pub inline fn setSizeLimits(self: Window, min: Size, max: Size) error{ InvalidVa getError() catch |err| return switch (err) { Error.InvalidValue, Error.PlatformError, - => @errSetCast(error{ InvalidValue, PlatformError }, err), + => err, else => unreachable, }; } @@ -734,13 +734,13 @@ pub inline fn setSizeLimits(self: Window, min: Size, max: Size) error{ InvalidVa /// @thread_safety This function must only be called from the main thread. /// /// see also: window_sizelimits, glfw.Window.setSizeLimits -pub inline fn setAspectRatio(self: Window, numerator: usize, denominator: usize) error{ InvalidValue, PlatformError }!void { +pub inline fn setAspectRatio(self: Window, numerator: usize, denominator: usize) Error!void { internal_debug.assertInitialized(); c.glfwSetWindowAspectRatio(self.handle, @intCast(c_int, numerator), @intCast(c_int, denominator)); getError() catch |err| return switch (err) { Error.InvalidValue, Error.PlatformError, - => @errSetCast(error{ InvalidValue, PlatformError }, err), + => err, else => unreachable, }; } @@ -755,13 +755,13 @@ pub inline fn setAspectRatio(self: Window, numerator: usize, denominator: usize) /// @thread_safety This function must only be called from the main thread. /// /// see also: window_fbsize, glfwWindow.setFramebufferSizeCallback -pub inline fn getFramebufferSize(self: Window) error{ PlatformError }!Size { +pub inline fn getFramebufferSize(self: Window) Error!Size { internal_debug.assertInitialized(); var width: c_int = 0; var height: c_int = 0; c.glfwGetFramebufferSize(self.handle, &width, &height); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) }; @@ -788,7 +788,7 @@ pub const FrameSize = struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_size -pub inline fn getFrameSize(self: Window) error{ PlatformError }!FrameSize { +pub inline fn getFrameSize(self: Window) Error!FrameSize { internal_debug.assertInitialized(); var left: c_int = 0; var top: c_int = 0; @@ -796,7 +796,7 @@ pub inline fn getFrameSize(self: Window) error{ PlatformError }!FrameSize { var bottom: c_int = 0; c.glfwGetWindowFrameSize(self.handle, &left, &top, &right, &bottom); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return FrameSize{ @@ -829,13 +829,13 @@ pub const ContentScale = struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_scale, glfwSetWindowContentScaleCallback, glfwGetMonitorContentScale -pub inline fn getContentScale(self: Window) error{ PlatformError }!ContentScale { +pub inline fn getContentScale(self: Window) Error!ContentScale { internal_debug.assertInitialized(); var x_scale: f32 = 0; var y_scale: f32 = 0; c.glfwGetWindowContentScale(self.handle, &x_scale, &y_scale); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return ContentScale{ .x_scale = x_scale, .y_scale = y_scale }; @@ -856,11 +856,11 @@ pub inline fn getContentScale(self: Window) error{ PlatformError }!ContentScale /// @thread_safety This function must only be called from the main thread. /// /// see also: window_transparency, glfw.Window.setOpacity -pub inline fn getOpacity(self: Window) error{ PlatformError }!f32 { +pub inline fn getOpacity(self: Window) Error!f32 { internal_debug.assertInitialized(); const opacity = c.glfwGetWindowOpacity(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return opacity; @@ -883,11 +883,11 @@ pub inline fn getOpacity(self: Window) error{ PlatformError }!f32 { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_transparency, glfw.Window.getOpacity -pub inline fn setOpacity(self: Window, opacity: f32) error{ PlatformError }!void { +pub inline fn setOpacity(self: Window, opacity: f32) Error!void { internal_debug.assertInitialized(); c.glfwSetWindowOpacity(self.handle, opacity); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -908,11 +908,11 @@ pub inline fn setOpacity(self: Window, opacity: f32) error{ PlatformError }!void /// @thread_safety This function must only be called from the main thread. /// /// see also: window_iconify, glfw.Window.restore, glfw.Window.maximize -pub inline fn iconify(self: Window) error{ PlatformError }!void { +pub inline fn iconify(self: Window) Error!void { internal_debug.assertInitialized(); c.glfwIconifyWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -930,11 +930,11 @@ pub inline fn iconify(self: Window) error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_iconify, glfw.Window.iconify, glfw.Window.maximize -pub inline fn restore(self: Window) error{ PlatformError }!void { +pub inline fn restore(self: Window) Error!void { internal_debug.assertInitialized(); c.glfwRestoreWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -951,11 +951,11 @@ pub inline fn restore(self: Window) error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_iconify, glfw.Window.iconify, glfw.Window.restore -pub inline fn maximize(self: Window) error{ PlatformError }!void { +pub inline fn maximize(self: Window) Error!void { internal_debug.assertInitialized(); c.glfwMaximizeWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -974,11 +974,11 @@ pub inline fn maximize(self: Window) error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_hide, glfw.Window.hide -pub inline fn show(self: Window) error{ PlatformError }!void { +pub inline fn show(self: Window) Error!void { internal_debug.assertInitialized(); c.glfwShowWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -993,11 +993,11 @@ pub inline fn show(self: Window) error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_hide, glfw.Window.show -pub inline fn hide(self: Window) error{ PlatformError }!void { +pub inline fn hide(self: Window) Error!void { internal_debug.assertInitialized(); c.glfwHideWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -1026,11 +1026,11 @@ pub inline fn hide(self: Window) error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_focus, window_attention -pub inline fn focus(self: Window) error{ PlatformError }!void { +pub inline fn focus(self: Window) Error!void { internal_debug.assertInitialized(); c.glfwFocusWindow(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -1050,11 +1050,11 @@ pub inline fn focus(self: Window) error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_attention -pub inline fn requestAttention(self: Window) error{ PlatformError }!void { +pub inline fn requestAttention(self: Window) Error!void { internal_debug.assertInitialized(); c.glfwRequestWindowAttention(self.handle); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -1080,13 +1080,13 @@ pub inline fn requestAttention(self: Window) error{ PlatformError }!void { /// @thread_safety This function may be called from any thread. /// /// see also: buffer_swap, glfwSwapInterval -pub inline fn swapBuffers(self: Window) error{ NoWindowContext, PlatformError }!void { +pub inline fn swapBuffers(self: Window) Error!void { internal_debug.assertInitialized(); c.glfwSwapBuffers(self.handle); getError() catch |err| return switch (err) { Error.NoWindowContext, Error.PlatformError, - => @errSetCast(error{ NoWindowContext, PlatformError }, err), + => err, else => unreachable, }; } @@ -1103,7 +1103,7 @@ pub inline fn swapBuffers(self: Window) error{ NoWindowContext, PlatformError }! /// /// see also: window_monitor, glfw.Window.setMonitor // TODO: Remove error stub -pub inline fn getMonitor(self: Window) error{}!?Monitor { +pub inline fn getMonitor(self: Window) Error!?Monitor { internal_debug.assertInitialized(); const monitor = c.glfwGetWindowMonitor(self.handle); getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible @@ -1153,7 +1153,7 @@ pub inline fn getMonitor(self: Window) error{}!?Monitor { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_monitor, window_full_screen, glfw.Window.getMonitor, glfw.Window.setSize -pub inline fn setMonitor(self: Window, monitor: ?Monitor, xpos: isize, ypos: isize, width: isize, height: isize, refresh_rate: isize) error{ PlatformError }!void { +pub inline fn setMonitor(self: Window, monitor: ?Monitor, xpos: isize, ypos: isize, width: isize, height: isize, refresh_rate: isize) Error!void { internal_debug.assertInitialized(); c.glfwSetWindowMonitor( self.handle, @@ -1165,7 +1165,7 @@ pub inline fn setMonitor(self: Window, monitor: ?Monitor, xpos: isize, ypos: isi @intCast(c_int, refresh_rate), ); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -1218,13 +1218,13 @@ pub const Attrib = enum(c_int) { /// @thread_safety This function must only be called from the main thread. /// /// see also: window_attribs, glfw.Window.setAttrib -pub inline fn getAttrib(self: Window, attrib: Attrib) error{ InvalidEnum, PlatformError }!isize { +pub inline fn getAttrib(self: Window, attrib: Attrib) Error!isize { internal_debug.assertInitialized(); const v = c.glfwGetWindowAttrib(self.handle, @enumToInt(attrib)); getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, PlatformError }, err), + => err, else => unreachable, }; return v; @@ -1255,14 +1255,14 @@ pub inline fn getAttrib(self: Window, attrib: Attrib) error{ InvalidEnum, Platfo /// see also: window_attribs, glfw.Window.getAttrib /// // TODO: Maybe enhance type-safety here to avoid 'InvalidEnum' and 'InvalidValue' at runtime alltogether? -pub inline fn setAttrib(self: Window, attrib: Attrib, value: bool) error{ InvalidEnum, InvalidValue, PlatformError }!void { +pub inline fn setAttrib(self: Window, attrib: Attrib, value: bool) Error!void { internal_debug.assertInitialized(); c.glfwSetWindowAttrib(self.handle, @enumToInt(attrib), if (value) c.GLFW_TRUE else c.GLFW_FALSE); getError() catch |err| return switch (err) { Error.InvalidEnum, Error.InvalidValue, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, InvalidValue, PlatformError }, err), + => err, else => unreachable, }; } @@ -1623,7 +1623,7 @@ pub const InputModeCursor = enum(c_int) { }; /// Sets the input mode of the cursor, whether it should behave normally, be hidden, or grabbed. -pub inline fn setInputModeCursor(self: Window, value: InputModeCursor) error{ InvalidEnum, PlatformError }!void { +pub inline fn setInputModeCursor(self: Window, value: InputModeCursor) Error!void { return self.setInputMode(InputMode.cursor, value); } @@ -1637,7 +1637,7 @@ pub inline fn getInputModeCursor(self: Window) InputModeCursor { /// /// This is useful when you are only interested in whether keys have been pressed but not when or /// in which order. -pub inline fn setInputModeStickyKeys(self: Window, enabled: bool) error{ InvalidEnum, PlatformError }!void { +pub inline fn setInputModeStickyKeys(self: Window, enabled: bool) Error!void { return self.setInputMode(InputMode.sticky_keys, enabled); } @@ -1652,7 +1652,7 @@ pub inline fn getInputModeStickyKeys(self: Window) bool { /// /// This is useful when you are only interested in whether buttons have been pressed but not when /// or in which order. -pub inline fn setInputModeStickyMouseButtons(self: Window, enabled: bool) error{ InvalidEnum, PlatformError }!void { +pub inline fn setInputModeStickyMouseButtons(self: Window, enabled: bool) Error!void { return self.setInputMode(InputMode.sticky_mouse_buttons, enabled); } @@ -1737,7 +1737,7 @@ pub inline fn getInputMode(self: Window, mode: InputMode) isize { /// @thread_safety This function must only be called from the main thread. /// /// see also: glfw.Window.getInputMode -pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) error{ InvalidEnum, PlatformError }!void { +pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) Error!void { internal_debug.assertInitialized(); switch (@typeInfo(@TypeOf(value))) { .Enum => c.glfwSetInputMode(self.handle, @enumToInt(mode), @enumToInt(value)), @@ -1748,7 +1748,7 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) error{ getError() catch |err| return switch (err) { Error.InvalidEnum, Error.PlatformError, - => @errSetCast(error{ InvalidEnum, PlatformError }, err), + => err, else => unreachable, }; } @@ -1779,11 +1779,11 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) error{ /// @thread_safety This function must only be called from the main thread. /// /// see also: input_key -pub inline fn getKey(self: Window, key: Key) error{ InvalidEnum }!Action { +pub inline fn getKey(self: Window, key: Key) Error!Action { internal_debug.assertInitialized(); const state = c.glfwGetKey(self.handle, @enumToInt(key)); getError() catch |err| return switch (err) { - Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err), + Error.InvalidEnum => err, else => unreachable, }; return @intToEnum(Action, state); @@ -1805,11 +1805,11 @@ pub inline fn getKey(self: Window, key: Key) error{ InvalidEnum }!Action { /// @thread_safety This function must only be called from the main thread. /// /// see also: input_mouse_button -pub inline fn getMouseButton(self: Window, button: MouseButton) error{ InvalidEnum }!Action { +pub inline fn getMouseButton(self: Window, button: MouseButton) Error!Action { internal_debug.assertInitialized(); const state = c.glfwGetMouseButton(self.handle, @enumToInt(button)); getError() catch |err| return switch (err) { - Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err), + Error.InvalidEnum => err, else => unreachable, }; return @intToEnum(Action, state); @@ -1845,12 +1845,12 @@ pub const CursorPos = struct { /// @thread_safety This function must only be called from the main thread. /// /// see also: cursor_pos, glfw.Window.setCursorPos -pub inline fn getCursorPos(self: Window) error{ PlatformError }!CursorPos { +pub inline fn getCursorPos(self: Window) Error!CursorPos { internal_debug.assertInitialized(); var pos: CursorPos = undefined; c.glfwGetCursorPos(self.handle, &pos.xpos, &pos.ypos); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return pos; @@ -1881,11 +1881,11 @@ pub inline fn getCursorPos(self: Window) error{ PlatformError }!CursorPos { /// @thread_safety This function must only be called from the main thread. /// /// see also: cursor_pos, glfw.Window.getCursorPos -pub inline fn setCursorPos(self: Window, xpos: f64, ypos: f64) error{ PlatformError }!void { +pub inline fn setCursorPos(self: Window, xpos: f64, ypos: f64) Error!void { internal_debug.assertInitialized(); c.glfwSetCursorPos(self.handle, xpos, ypos); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -1905,11 +1905,11 @@ pub inline fn setCursorPos(self: Window, xpos: f64, ypos: f64) error{ PlatformEr /// @thread_safety This function must only be called from the main thread. /// /// see also: cursor_object -pub inline fn setCursor(self: Window, cursor: Cursor) error{ PlatformError }!void { +pub inline fn setCursor(self: Window, cursor: Cursor) Error!void { internal_debug.assertInitialized(); c.glfwSetCursor(self.handle, cursor.ptr); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -2159,7 +2159,7 @@ fn setDropCallbackWrapper(handle: ?*c.GLFWwindow, path_count: c_int, paths: [*c] /// /// see also: path_drop // TODO: Remove error stub -pub inline fn setDropCallback(self: Window, callback: ?fn (window: Window, paths: [][*:0]const u8) void) error{}!void { +pub inline fn setDropCallback(self: Window, callback: ?fn (window: Window, paths: [][*:0]const u8) void) Error!void { internal_debug.assertInitialized(); var internal = self.getInternal(); internal.setDropCallback = callback; diff --git a/glfw/src/clipboard.zig b/glfw/src/clipboard.zig index 7f4c671c..1a1b9c6e 100644 --- a/glfw/src/clipboard.zig +++ b/glfw/src/clipboard.zig @@ -19,11 +19,11 @@ const internal_debug = @import("internal_debug.zig"); /// @thread_safety This function must only be called from the main thread. /// /// see also: clipboard, glfwGetClipboardString -pub inline fn setClipboardString(value: [*:0]const u8) error{ PlatformError }!void { +pub inline fn setClipboardString(value: [*:0]const u8) Error!void { internal_debug.assertInitialized(); c.glfwSetClipboardString(null, value); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -45,11 +45,11 @@ pub inline fn setClipboardString(value: [*:0]const u8) error{ PlatformError }!vo /// @thread_safety This function must only be called from the main thread. /// /// see also: clipboard, glfwSetClipboardString -pub inline fn getClipboardString() error{ PlatformError }![:0]const u8 { +pub inline fn getClipboardString() Error![:0]const u8 { internal_debug.assertInitialized(); const value = c.glfwGetClipboardString(null); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return std.mem.span(value); diff --git a/glfw/src/key.zig b/glfw/src/key.zig index a92bc94a..26c68657 100644 --- a/glfw/src/key.zig +++ b/glfw/src/key.zig @@ -214,11 +214,11 @@ pub const Key = enum(c_int) { /// @thread_safety This function must only be called from the main thread. /// /// see also: input_key_name - pub inline fn getName(self: Key, scancode: isize) error{ PlatformError }!?[:0]const u8 { + pub inline fn getName(self: Key, scancode: isize) Error!?[:0]const u8 { internal_debug.assertInitialized(); const name_opt = cc.glfwGetKeyName(@enumToInt(self), @intCast(c_int, scancode)); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return if (name_opt) |name| @@ -239,12 +239,12 @@ pub const Key = enum(c_int) { /// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError. /// /// @thread_safety This function may be called from any thread. - pub inline fn getScancode(self: Key) error{ PlatformError }!isize { + pub inline fn getScancode(self: Key) Error!isize { internal_debug.assertInitialized(); const scancode = cc.glfwGetKeyScancode(@enumToInt(self)); getError() catch |err| return switch (err) { Error.InvalidEnum => unreachable, // Should be unreachable for any valid 'Key' value. - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; return scancode; diff --git a/glfw/src/main.zig b/glfw/src/main.zig index 8412f484..550ddefe 100644 --- a/glfw/src/main.zig +++ b/glfw/src/main.zig @@ -57,7 +57,7 @@ const internal_debug = @import("internal_debug.zig"); /// Unicode text input. /// /// @thread_safety This function must only be called from the main thread. -pub inline fn init(hints: InitHints) error{ PlatformError }!void { +pub inline fn init(hints: InitHints) Error!void { internal_debug.toggleInitialized(); internal_debug.assertInitialized(); errdefer internal_debug.toggleInitialized(); @@ -76,7 +76,7 @@ pub inline fn init(hints: InitHints) error{ PlatformError }!void { _ = c.glfwInit(); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -173,7 +173,7 @@ const InitHint = enum(c_int) { /// @remarks This function may be called before glfw.init. /// /// @thread_safety This function must only be called from the main thread. -fn initHint(hint: InitHint, value: anytype) error{ InvalidValue }!void { +fn initHint(hint: InitHint, value: anytype) Error!void { switch (@typeInfo(@TypeOf(value))) { .Int, .ComptimeInt => c.glfwInitHint(@enumToInt(hint), @intCast(c_int, value)), .Bool => c.glfwInitHint(@enumToInt(hint), @intCast(c_int, @boolToInt(value))), @@ -181,7 +181,7 @@ fn initHint(hint: InitHint, value: anytype) error{ InvalidValue }!void { } getError() catch |err| return switch (err) { Error.InvalidEnum => unreachable, // impossible for any valid 'InitHint' value - Error.InvalidValue => @errSetCast(error{ InvalidValue }, err), + Error.InvalidValue => err, else => unreachable, }; } @@ -233,11 +233,11 @@ pub inline fn getVersionString() [:0]const u8 { /// @thread_safety This function must only be called from the main thread. /// /// see also: events, glfw.waitEvents, glfw.waitEventsTimeout -pub inline fn pollEvents() error{ PlatformError }!void { +pub inline fn pollEvents() Error!void { internal_debug.assertInitialized(); c.glfwPollEvents(); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -272,11 +272,11 @@ pub inline fn pollEvents() error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: events, glfw.pollEvents, glfw.waitEventsTimeout -pub inline fn waitEvents() error{ PlatformError }!void { +pub inline fn waitEvents() Error!void { internal_debug.assertInitialized(); c.glfwWaitEvents(); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } @@ -315,7 +315,7 @@ pub inline fn waitEvents() error{ PlatformError }!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: events, glfw.pollEvents, glfw.waitEvents -pub inline fn waitEventsTimeout(timeout: f64) error{ InvalidValue, PlatformError }!void { +pub inline fn waitEventsTimeout(timeout: f64) Error!void { internal_debug.assertInitialized(); c.glfwWaitEventsTimeout(timeout); getError() catch |err| return switch (err) { @@ -323,7 +323,7 @@ pub inline fn waitEventsTimeout(timeout: f64) error{ InvalidValue, PlatformError // and make its branch unreachable. Error.InvalidValue, Error.PlatformError, - => @errSetCast(error{ InvalidValue, PlatformError }, err), + => err, else => unreachable, }; } @@ -338,11 +338,11 @@ pub inline fn waitEventsTimeout(timeout: f64) error{ InvalidValue, PlatformError /// @thread_safety This function may be called from any thread. /// /// see also: events, glfw.waitEvents, glfw.waitEventsTimeout -pub inline fn postEmptyEvent() error{ PlatformError }!void { +pub inline fn postEmptyEvent() Error!void { internal_debug.assertInitialized(); c.glfwPostEmptyEvent(); getError() catch |err| return switch (err) { - Error.PlatformError => @errSetCast(error{ PlatformError }, err), + Error.PlatformError => err, else => unreachable, }; } diff --git a/glfw/src/opengl.zig b/glfw/src/opengl.zig index 8507352c..de5d4d1a 100644 --- a/glfw/src/opengl.zig +++ b/glfw/src/opengl.zig @@ -31,13 +31,13 @@ const internal_debug = @import("internal_debug.zig"); /// @thread_safety This function may be called from any thread. /// /// see also: context_current, glfwGetCurrentContext -pub inline fn makeContextCurrent(window: ?Window) error{ NoWindowContext, PlatformError }!void { +pub inline fn makeContextCurrent(window: ?Window) Error!void { internal_debug.assertInitialized(); if (window) |w| c.glfwMakeContextCurrent(w.handle) else c.glfwMakeContextCurrent(null); getError() catch |err| return switch (err) { Error.NoWindowContext, Error.PlatformError, - => @errSetCast(error{ NoWindowContext, PlatformError }, err), + => err, else => unreachable, }; } @@ -95,13 +95,13 @@ pub inline fn getCurrentContext() std.mem.Allocator.Error!?Window { /// @thread_safety This function may be called from any thread. /// /// see also: buffer_swap, glfwSwapBuffers -pub inline fn swapInterval(interval: isize) error{ NoCurrentContext, PlatformError }!void { +pub inline fn swapInterval(interval: isize) Error!void { internal_debug.assertInitialized(); c.glfwSwapInterval(@intCast(c_int, interval)); getError() catch |err| return switch (err) { Error.NoCurrentContext, Error.PlatformError, - => @errSetCast(error{ NoCurrentContext, PlatformError }, err), + => err, else => unreachable, }; } @@ -131,13 +131,13 @@ pub inline fn swapInterval(interval: isize) error{ NoCurrentContext, PlatformErr /// @thread_safety This function may be called from any thread. /// /// see also: context_glext, glfw.getProcAddress -pub inline fn extensionSupported(extension: [*:0]const u8) error{ NoCurrentContext, InvalidValue }!bool { +pub inline fn extensionSupported(extension: [*:0]const u8) Error!bool { internal_debug.assertInitialized(); const supported = c.glfwExtensionSupported(extension); getError() catch |err| return switch (err) { Error.NoCurrentContext, Error.InvalidValue, - => @errSetCast(error{ NoCurrentContext, InvalidValue }, err), + => err, else => unreachable, }; return supported == c.GLFW_TRUE; diff --git a/glfw/src/time.zig b/glfw/src/time.zig index 1a22f3c8..ba33893d 100644 --- a/glfw/src/time.zig +++ b/glfw/src/time.zig @@ -53,12 +53,12 @@ pub inline fn getTime() f64 { /// base time is not atomic, so it needs to be externally synchronized with calls to glfw.getTime. /// /// see also: time -pub inline fn setTime(time: f64) error{ InvalidValue }!void { +pub inline fn setTime(time: f64) Error!void { internal_debug.assertInitialized(); c.glfwSetTime(time); getError() catch |err| return switch (err) { // TODO: Consider whether to use GLFW error handling, or assert that 'time' is a valid value - Error.InvalidValue => @errSetCast(error{ InvalidValue }, err), + Error.InvalidValue => err, else => unreachable, }; } diff --git a/glfw/src/vulkan.zig b/glfw/src/vulkan.zig index 6bb62a80..6a2ab604 100644 --- a/glfw/src/vulkan.zig +++ b/glfw/src/vulkan.zig @@ -25,7 +25,7 @@ const internal_debug = @import("internal_debug.zig"); /// /// @thread_safety This function may be called from any thread. // TODO: Remove error stub -pub inline fn vulkanSupported() error{}!bool { +pub inline fn vulkanSupported() Error!bool { internal_debug.assertInitialized(); const supported = c.glfwVulkanSupported(); getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible @@ -61,12 +61,12 @@ pub inline fn vulkanSupported() error{}!bool { /// @thread_safety This function may be called from any thread. /// /// see also: vulkan_ext, glfwCreateWindowSurface -pub inline fn getRequiredInstanceExtensions() error{ APIUnavailable }![][*:0]const u8 { +pub inline fn getRequiredInstanceExtensions() Error![][*:0]const u8 { internal_debug.assertInitialized(); var count: u32 = 0; const extensions = c.glfwGetRequiredInstanceExtensions(&count); getError() catch |err| return switch (err) { - Error.APIUnavailable => @errSetCast(error{ APIUnavailable }, err), + Error.APIUnavailable => err, else => unreachable, }; return @ptrCast([*][*:0]const u8, extensions)[0..count]; @@ -143,7 +143,7 @@ pub fn getInstanceProcAddress(vk_instance: ?*opaque {}, proc_name: [*:0]const u8 /// Vulkan objects, see the Vulkan specification. /// /// see also: vulkan_present -pub inline fn getPhysicalDevicePresentationSupport(vk_instance: *opaque {}, vk_physical_device: *opaque {}, queue_family: u32) error{ APIUnavailable, PlatformError }!bool { +pub inline fn getPhysicalDevicePresentationSupport(vk_instance: *opaque {}, vk_physical_device: *opaque {}, queue_family: u32) Error!bool { internal_debug.assertInitialized(); const v = c.glfwGetPhysicalDevicePresentationSupport( @ptrCast(c.VkInstance, vk_instance), @@ -153,7 +153,7 @@ pub inline fn getPhysicalDevicePresentationSupport(vk_instance: *opaque {}, vk_p getError() catch |err| return switch (err) { Error.APIUnavailable, Error.PlatformError, - => @errSetCast(error{ APIUnavailable, PlatformError }, err), + => err, else => unreachable, }; return v == c.GLFW_TRUE; @@ -204,7 +204,7 @@ pub inline fn getPhysicalDevicePresentationSupport(vk_instance: *opaque {}, vk_p /// Vulkan objects, see the Vulkan specification. /// /// see also: vulkan_surface, glfw.getRequiredInstanceExtensions -pub inline fn createWindowSurface(vk_instance: anytype, window: Window, vk_allocation_callbacks: anytype, vk_surface_khr: anytype) error{ APIUnavailable, PlatformError, InvalidValue }!i32 { +pub inline fn createWindowSurface(vk_instance: anytype, window: Window, vk_allocation_callbacks: anytype, vk_surface_khr: anytype) Error!i32 { internal_debug.assertInitialized(); // zig-vulkan uses enums to represent opaque pointers: // pub const Instance = enum(usize) { null_handle = 0, _ };