From 5680de7d8ccb1bffeb3c9fc77e0e534d8f3b82fc Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Thu, 2 Apr 2026 15:57:16 +0200 Subject: [PATCH] opengl: move dynload macro to macros.rs --- src/gfx_apis/gl.rs | 47 ---------------------------------------------- src/macros.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/gfx_apis/gl.rs b/src/gfx_apis/gl.rs index 1e974f6a..5f1b63e3 100644 --- a/src/gfx_apis/gl.rs +++ b/src/gfx_apis/gl.rs @@ -18,53 +18,6 @@ macro_rules! egl_transparent { }; } -macro_rules! dynload { - ( - $item:ident: $container:ident from $name:literal { - $( - $fun:ident: $ty:ty, - )* - } - ) => { - #[expect(non_snake_case)] - #[derive(Debug)] - pub struct $container { - _lib: libloading::Library, - $( - pub $fun: $ty, - )* - } - - pub static $item: std::sync::LazyLock> = std::sync::LazyLock::new(|| unsafe { - use crate::utils::errorfmt::ErrorFmt; - let lib = match libloading::Library::new($name) { - Ok(l) => l, - Err(e) => { - log::error!("Could not load lib{}: {}", $name, ErrorFmt(e)); - return None; - } - }; - $( - #[expect(non_snake_case)] - let $fun: $ty = - match lib.get(stringify!($fun).as_bytes()) { - Ok(s) => *s, - Err(e) => { - log::error!("Could not load {} from {}: {}", stringify!($fun), $name, ErrorFmt(e)); - return None; - } - }; - )* - Some($container { - _lib: lib, - $( - $fun, - )* - }) - }); - }; -} - use { crate::{ cmm::cmm_eotf::Eotf, diff --git a/src/macros.rs b/src/macros.rs index 99fd01a4..7b04569b 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -853,3 +853,50 @@ macro_rules! dbg { } }; } + +macro_rules! dynload { + ( + $item:ident: $container:ident from $name:literal { + $( + $fun:ident: $ty:ty, + )* + } + ) => { + #[expect(non_snake_case)] + #[derive(Debug)] + pub struct $container { + _lib: libloading::Library, + $( + pub $fun: $ty, + )* + } + + pub static $item: std::sync::LazyLock> = std::sync::LazyLock::new(|| unsafe { + use crate::utils::errorfmt::ErrorFmt; + let lib = match libloading::Library::new($name) { + Ok(l) => l, + Err(e) => { + log::error!("Could not load {}: {}", $name, ErrorFmt(e)); + return None; + } + }; + $( + #[allow(clippy::allow_attributes, non_snake_case)] + let $fun: $ty = + match lib.get(stringify!($fun).as_bytes()) { + Ok(s) => *s, + Err(e) => { + log::error!("Could not load {} from {}: {}", stringify!($fun), $name, ErrorFmt(e)); + return None; + } + }; + )* + Some($container { + _lib: lib, + $( + $fun, + )* + }) + }); + }; +}