glfw: document why unreachable is valid

This commit is contained in:
Lee Cannon 2022-02-09 21:45:27 +00:00 committed by Stephen Gutekanst
parent 0cdac6c68a
commit bc8ce57e53
8 changed files with 36 additions and 1 deletions

View file

@ -69,6 +69,7 @@ pub inline fn create(image: Image, xhot: i32, yhot: i32) error{PlatformError}!Cu
Error.PlatformError => |e| e, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwCreateCursor` returns `null` only for errors
unreachable; unreachable;
} }
@ -90,6 +91,7 @@ pub inline fn createStandard(shape: Shape) error{PlatformError}!Cursor {
Error.PlatformError => |e| e, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwCreateStandardCursor` returns `null` only for errors
unreachable; unreachable;
} }

View file

@ -169,6 +169,7 @@ pub inline fn getName(self: Monitor) [*:0]const u8 {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetMonitorName` returns `null` only for errors
unreachable; unreachable;
} }
@ -247,6 +248,7 @@ pub inline fn getVideoModes(self: Monitor, allocator: mem.Allocator) (mem.Alloca
Error.PlatformError => |e| e, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetVideoModes` returns `null` only for errors
unreachable; unreachable;
} }
@ -269,6 +271,7 @@ pub inline fn getVideoMode(self: Monitor) error{PlatformError}!VideoMode {
Error.PlatformError => |e| e, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetVideoMode` returns `null` only for errors
unreachable; unreachable;
} }
@ -330,6 +333,7 @@ pub inline fn getGammaRamp(self: Monitor) error{PlatformError}!GammaRamp {
Error.PlatformError => |e| e, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetGammaRamp` returns `null` only for errors
unreachable; unreachable;
} }

View file

@ -444,7 +444,7 @@ pub inline fn create(
else => unreachable, else => unreachable,
}; };
// `glfwCreateWindow` returns `null` only for errors
unreachable; unreachable;
} }
@ -1304,6 +1304,7 @@ pub inline fn getAttrib(self: Window, attrib: Attrib) error{PlatformError}!i32 {
Error.PlatformError => |e| e, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// this is not unreachable as `0` is a valid value
return v; return v;
} }

View file

@ -54,6 +54,7 @@ pub inline fn getClipboardString() error{ FormatUnavailable, PlatformError }![:0
Error.FormatUnavailable, Error.PlatformError => |e| e, Error.FormatUnavailable, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetClipboardString` returns `null` only for errors
unreachable; unreachable;
} }

View file

@ -250,6 +250,7 @@ pub const Key = enum(c_int) {
Error.PlatformError => |e| e, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetKeyScancode` returns `-1` only for errors
unreachable; unreachable;
} }
}; };

View file

@ -72,6 +72,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetWin32Adapter` returns `null` only for errors
unreachable; unreachable;
} }
@ -90,6 +91,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetWin32Monitor` returns `null` only for errors
unreachable; unreachable;
} }
@ -114,6 +116,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetWin32Window` returns `null` only for errors
unreachable; unreachable;
} }
@ -138,6 +141,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NoWindowContext => |e| e, Error.NoWindowContext => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetWGLContext` returns `null` only for errors
unreachable; unreachable;
} }
@ -154,6 +158,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetCocoaMonitor` returns `kCGNullDirectDisplay` only for errors
unreachable; unreachable;
} }
@ -200,6 +205,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetX11Display` returns `null` only for errors
unreachable; unreachable;
} }
@ -216,6 +222,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetX11Adapter` returns `0` only for errors
unreachable; unreachable;
} }
@ -232,6 +239,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetX11Monitor` returns `0` only for errors
unreachable; unreachable;
} }
@ -248,6 +256,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetX11Window` returns `0` only for errors
unreachable; unreachable;
} }
@ -285,6 +294,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.FormatUnavailable => |e| e, Error.FormatUnavailable => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetX11SelectionString` returns `null` only for errors
unreachable; unreachable;
} }
@ -301,6 +311,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NoWindowContext => |e| e, Error.NoWindowContext => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetGLXContext` returns `null` only for errors
unreachable; unreachable;
} }
@ -318,6 +329,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NoWindowContext => |e| e, Error.NoWindowContext => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetGLXWindow` returns `0` only for errors
unreachable; unreachable;
} }
@ -333,6 +345,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetWaylandDisplay` returns `null` only for errors
unreachable; unreachable;
} }
@ -348,6 +361,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetWaylandMonitor` returns `null` only for errors
unreachable; unreachable;
} }
@ -363,6 +377,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetWaylandWindow` returns `null` only for errors
unreachable; unreachable;
} }
@ -379,6 +394,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetEGLDisplay` returns `EGL_NO_DISPLAY` only for errors
unreachable; unreachable;
} }
@ -396,6 +412,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NoWindowContext => |e| e, Error.NoWindowContext => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetEGLContext` returns `EGL_NO_CONTEXT` only for errors
unreachable; unreachable;
} }
@ -413,6 +430,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NoWindowContext => |e| e, Error.NoWindowContext => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetEGLSurface` returns `EGL_NO_SURFACE` only for errors
unreachable; unreachable;
} }
@ -444,6 +462,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.PlatformError, Error.NoWindowContext => |e| e, Error.PlatformError, Error.NoWindowContext => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetOSMesaColorBuffer` returns `GLFW_FALSE` only for errors
unreachable; unreachable;
} }
@ -475,6 +494,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.PlatformError, Error.NoWindowContext => |e| e, Error.PlatformError, Error.NoWindowContext => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetOSMesaDepthBuffer` returns `GLFW_FALSE` only for errors
unreachable; unreachable;
} }
@ -491,6 +511,7 @@ pub fn Native(comptime options: BackendOptions) type {
Error.NoWindowContext => |e| e, Error.NoWindowContext => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetOSMesaContext` returns `null` only for errors
unreachable; unreachable;
} }
}; };

View file

@ -35,6 +35,7 @@ pub inline fn getTime() f64 {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetTime` returns `0` only for errors
unreachable; unreachable;
} }
@ -94,6 +95,7 @@ pub inline fn getTimerValue() u64 {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetTimerValue` returns `0` only for errors
unreachable; unreachable;
} }
@ -114,6 +116,7 @@ pub inline fn getTimerFrequency() u64 {
Error.NotInitialized => unreachable, Error.NotInitialized => unreachable,
else => unreachable, else => unreachable,
}; };
// `glfwGetTimerFrequency` returns `0` only for errors
unreachable; unreachable;
} }

View file

@ -68,6 +68,7 @@ pub inline fn getRequiredInstanceExtensions() error{APIUnavailable}![][*:0]const
Error.APIUnavailable => |e| e, Error.APIUnavailable => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwGetRequiredInstanceExtensions` returns `null` only for errors
unreachable; unreachable;
} }
@ -227,6 +228,7 @@ pub inline fn createWindowSurface(vk_instance: anytype, window: Window, vk_alloc
Error.APIUnavailable, Error.PlatformError => |e| e, Error.APIUnavailable, Error.PlatformError => |e| e,
else => unreachable, else => unreachable,
}; };
// `glfwCreateWindowSurface` returns `!VK_SUCCESS` only for errors
unreachable; unreachable;
} }