From 900eedec1e5b60e17054bc98bd3b16ad07a9fe2c Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Mon, 29 Jan 2024 11:01:32 -0500 Subject: [PATCH] Add num-traits support for enums --- Cargo.toml | 6 +++++- build/bind.rs | 2 +- build/wrap/enums.rs | 9 +-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 74bcef4..b08a580 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "raylib-ffi" -version = "5.0.0" +version = "5.0.1" authors = ["Evan Pratten "] edition = "2021" description = "Automatic raw Rust bindings to raylib" @@ -18,6 +18,10 @@ exclude = [ ] build = "build/main.rs" +[dependencies] +num-traits = "0.2.17" +num-derive = "0.4.1" + [build-dependencies] bindgen = "0.69.1" cmake = "^0.1.49" diff --git a/build/bind.rs b/build/bind.rs index cda6824..f6672b8 100644 --- a/build/bind.rs +++ b/build/bind.rs @@ -85,7 +85,7 @@ pub fn generate_bindings(header_file: &str) { // Construct a builder for generating bindings let mut builder = bindgen::Builder::default() .header(header_file) - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .blocklist_item("DEG2RAD") .blocklist_item("PI") .blocklist_item("RAD2DEG") diff --git a/build/wrap/enums.rs b/build/wrap/enums.rs index 41c4333..c931ac6 100644 --- a/build/wrap/enums.rs +++ b/build/wrap/enums.rs @@ -63,7 +63,7 @@ pub fn wrap_exposed_enums(api_defs: RayLibApiDefinition) { // Write the enum declaration lines.push("#[repr(C)]".to_string()); - lines.push("#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]".to_string()); + lines.push("#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, num_derive::FromPrimitive, num_derive::ToPrimitive)]".to_string()); lines.push(format!("pub enum {} {{", en.name)); // Write each enum variant @@ -94,13 +94,6 @@ pub fn wrap_exposed_enums(api_defs: RayLibApiDefinition) { // Close the enum declaration lines.push("}".to_string()); - - // Write a conversion function - lines.push(format!("impl Into for {} {{", en.name)); - lines.push(format!("\tfn into(self) -> usize {{")); - lines.push(format!("\t\tself as usize")); - lines.push(format!("\t}}")); - lines.push(format!("}}")); } // Write the output file