diff --git a/Cargo.lock b/Cargo.lock index acf76cb..074cefb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,12 +42,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - [[package]] name = "cfg-if" version = "1.0.0" @@ -77,7 +71,7 @@ version = "24.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8add37afff2d4ffa83bc748a70b4b1370984f6980768554182424ef71447c35f" dependencies = [ - "bitflags 1.3.2", + "bitflags", "rustc_version", ] @@ -103,9 +97,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "indoc" @@ -125,16 +119,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memoffset" version = "0.9.1" @@ -150,29 +134,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "portable-atomic" version = "1.6.0" @@ -225,15 +186,15 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "1962a33ed2a201c637fc14a4e0fd4e06e6edfdeee6a5fede0dab55507ad74cf7" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -243,9 +204,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "ab7164b2202753bd33afc7f90a10355a719aa973d1f94502c50d06f3488bc420" dependencies = [ "once_cell", "target-lexicon", @@ -253,9 +214,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "c6424906ca49013c0829c5c1ed405e20e2da2dc78b82d198564880a704e6a7b7" dependencies = [ "libc", "pyo3-build-config", @@ -263,9 +224,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "82b2f19e153122d64afd8ce7aaa72f06a00f52e34e1d1e74b6d71baea396460a" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -275,9 +236,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "dd698c04cac17cf0fe63d47790ab311b8b25542f5cb976b65c374035c50f1eef" dependencies = [ "heck", "proc-macro2", @@ -318,15 +279,6 @@ dependencies = [ "syn 2.0.67", ] -[[package]] -name = "redox_syscall" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" -dependencies = [ - "bitflags 2.5.0", -] - [[package]] name = "rlbot-flatbuffers-py" version = "0.4.0" @@ -346,12 +298,6 @@ dependencies = [ "semver", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "semver" version = "1.0.23" @@ -428,67 +374,3 @@ name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/Cargo.toml b/Cargo.toml index 7d2cb38..89e430b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ name = "rlbot_flatbuffers" crate-type = ["cdylib"] [dependencies] -pyo3 = "0.21.0" +pyo3 = { version = "0.22.0", features = ["py-clone"] } serde = "1.0.197" flatbuffers = "24.3.25" get-size = { version = "0.1.4", features = ["derive"] } diff --git a/codegen/enums.rs b/codegen/enums.rs index b0f52d8..1b51d3b 100644 --- a/codegen/enums.rs +++ b/codegen/enums.rs @@ -206,12 +206,6 @@ impl EnumBindGenerator { ); write_str!(self, " }"); } - - fn generate_enum_hash_method(&mut self) { - write_str!(self, " pub fn __hash__(&self) -> u64 {"); - write_str!(self, " crate::hash_u8(*self as u8)"); - write_str!(self, " }"); - } } impl Generator for EnumBindGenerator { @@ -247,8 +241,11 @@ impl Generator for EnumBindGenerator { fn generate_definition(&mut self) { write_str!(self, "#[allow(non_camel_case_types)]"); - write_str!(self, "#[pyclass(module = \"rlbot_flatbuffers\", frozen)]"); - write_str!(self, "#[derive(Debug, Default, Clone, Copy)]"); + write_str!( + self, + "#[pyclass(module = \"rlbot_flatbuffers\", frozen, hash, eq, eq_int)]" + ); + write_str!(self, "#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]"); write_fmt!(self, "pub enum {} {{", self.struct_name); write_str!(self, " #[default]"); @@ -329,7 +326,6 @@ impl Generator for EnumBindGenerator { self.generate_repr_method(); write_str!(self, ""); - self.generate_enum_hash_method(); write_str!(self, "}"); write_str!(self, ""); } diff --git a/codegen/pyi.rs b/codegen/pyi.rs index 03e4f52..249d907 100644 --- a/codegen/pyi.rs +++ b/codegen/pyi.rs @@ -86,8 +86,9 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> { write_str!(file, " def __int__(self) -> int: ..."); write_fmt!( file, - " def __richcmp__(self, other: {type_name}, op: int) -> bool: ..." + " def __eq__(self, other: {type_name}) -> bool: ..." ); + write_str!(file, " def __hash__(self) -> str: ..."); } PythonBindType::Struct(gen) => { let mut python_types = Vec::new(); @@ -216,7 +217,6 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> { write_str!(file, " def __str__(self) -> str: ..."); write_str!(file, " def __repr__(self) -> str: ..."); - write_str!(file, " def __hash__(self) -> str: ..."); if !(matches!(item, PythonBindType::Union { .. })) { write_str!(file, " def pack(self) -> bytes: ..."); diff --git a/codegen/structs.rs b/codegen/structs.rs index 17a97a3..a804cef 100644 --- a/codegen/structs.rs +++ b/codegen/structs.rs @@ -596,7 +596,7 @@ impl Generator for StructBindGenerator { ); if self.types.is_empty() { - write_str!(self, "#[derive(Debug, Default, Clone)]"); + write_str!(self, "#[derive(Debug, Default, Clone, Copy)]"); write_fmt!(self, "pub struct {} {{}}", self.struct_name); write_str!(self, ""); return; diff --git a/src/lib.rs b/src/lib.rs index 3021de2..6cdf0d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,10 +14,7 @@ mod python; use pyo3::{create_exception, exceptions::PyValueError, prelude::*, types::PyBytes, PyClass}; use python::*; -use std::{ - hash::{DefaultHasher, Hash, Hasher}, - panic::Location, -}; +use std::panic::Location; create_exception!(rlbot_flatbuffers, InvalidFlatbuffer, PyValueError, "Invalid FlatBuffer"); @@ -31,12 +28,6 @@ pub fn flat_err_to_py(err: flatbuffers::InvalidFlatbuffer) -> PyErr { InvalidFlatbuffer::new_err(err_msg) } -pub fn hash_u8(num: u8) -> u64 { - let mut hasher = DefaultHasher::new(); - num.hash(&mut hasher); - hasher.finish() -} - pub trait FromGil { fn from_gil(py: Python, obj: T) -> Self; } @@ -113,7 +104,7 @@ pub const fn bool_to_str(b: bool) -> &'static str { } } -#[derive(Debug, Clone, FromPyObject)] +#[derive(Debug, FromPyObject)] pub enum Floats { Flat(Py), Num(f32), @@ -134,7 +125,7 @@ impl FromGil for Py { } } -#[derive(Debug, Clone, FromPyObject)] +#[derive(Debug, FromPyObject)] pub enum Bools { Flat(Py), Num(bool),