Skip to content

Commit

Permalink
Add num-traits support for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ewpratten committed Jan 29, 2024
1 parent f976ee2 commit 900eede
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "raylib-ffi"
version = "5.0.0"
version = "5.0.1"
authors = ["Evan Pratten <ewpratten@gmail.com>"]
edition = "2021"
description = "Automatic raw Rust bindings to raylib"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion build/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 1 addition & 8 deletions build/wrap/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<usize> 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
Expand Down

0 comments on commit 900eede

Please sign in to comment.