From 9b614eaae34c723f6d2b5e19403986624ff5cf76 Mon Sep 17 00:00:00 2001 From: ararem <48875125+Ararem@users.noreply.github.com> Date: Wed, 4 Jan 2023 13:00:42 +0100 Subject: [PATCH] Implement DataTypeKind for `usize` and `isize` This allows direct use of the size types in `imgui-rs` functions, like `Slider`s. Previously, they had to be cast, passed in, then cast back. This change allows for direct use (no casts necessary) --- imgui/src/internal.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/imgui/src/internal.rs b/imgui/src/internal.rs index 0af90a1..bcb7e6a 100644 --- a/imgui/src/internal.rs +++ b/imgui/src/internal.rs @@ -165,3 +165,43 @@ unsafe impl DataTypeKind for f32 { unsafe impl DataTypeKind for f64 { const KIND: DataType = DataType::F64; } + +unsafe impl DataTypeKind for usize { + #[cfg(target_pointer_width = "16")] + const KIND: DataType = DataType::U16; + + #[cfg(target_pointer_width = "32")] + const KIND: DataType = DataType::U32; + + #[cfg(target_pointer_width = "64")] + const KIND: DataType = DataType::U64; + + // Fallback for when we are on a weird system width + // + #[cfg(not(any( + target_pointer_width = "16", + target_pointer_width = "32", + target_pointer_width = "64" + )))] + compile_error!("cannot impl DataTypeKind for usize: unsupported target pointer width. supported values are 16, 32, 64"); +} + +unsafe impl DataTypeKind for isize { + #[cfg(target_pointer_width = "16")] + const KIND: DataType = DataType::I16; + + #[cfg(target_pointer_width = "32")] + const KIND: DataType = DataType::I32; + + #[cfg(target_pointer_width = "64")] + const KIND: DataType = DataType::I64; + + // Fallback for when we are on a weird system width + // + #[cfg(not(any( + target_pointer_width = "16", + target_pointer_width = "32", + target_pointer_width = "64" + )))] + compile_error!("cannot impl DataTypeKind for isize: unsupported target pointer width. supported values are 16, 32, 64"); +}