1

Add num-traits support for enums

This commit is contained in:
Evan Pratten 2024-01-29 11:01:32 -05:00
parent f976ee2333
commit 900eedec1e
3 changed files with 7 additions and 10 deletions

View File

@ -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"
@ -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"

View File

@ -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")

View File

@ -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<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