Use safer_ffi for repr C trait

This commit is contained in:
hodasemi 2023-01-27 11:58:55 +01:00
parent d5e765db61
commit c131cb9bac
7 changed files with 32 additions and 12 deletions

View file

@ -30,6 +30,7 @@ serde = { version = "1.0", features = ["serde_derive"], optional = true }
# works only in rust toolchain up to 1.32, disabled indefinitely # works only in rust toolchain up to 1.32, disabled indefinitely
#simd = { version = "0.2", optional = true } #simd = { version = "0.2", optional = true }
bytemuck = { version = "1.0", optional = true } bytemuck = { version = "1.0", optional = true }
safer-ffi = { version = "0.0.10", features = ["proc_macros"] }
[dev-dependencies] [dev-dependencies]
serde_json = "1.0" serde_json = "1.0"

View file

@ -28,10 +28,11 @@ use approx;
use mint; use mint;
use num::BaseFloat; use num::BaseFloat;
use quaternion::Quaternion; use quaternion::Quaternion;
use safer_ffi::prelude::*;
/// A set of [Euler angles] representing a rotation in three-dimensional space. /// A set of [Euler angles] representing a rotation in three-dimensional space.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
/// ///
/// The axis rotation sequence is XYZ. That is, the rotation is first around /// The axis rotation sequence is XYZ. That is, the rotation is first around
/// the X axis, then the Y axis, and lastly the Z axis (using intrinsic /// the X axis, then the Y axis, and lastly the Z axis (using intrinsic
@ -78,6 +79,7 @@ use quaternion::Quaternion;
/// [Euler angles]: https://en.wikipedia.org/wiki/Euler_angles /// [Euler angles]: https://en.wikipedia.org/wiki/Euler_angles
/// [gimbal lock]: https://en.wikipedia.org/wiki/Gimbal_lock#Gimbal_lock_in_applied_mathematics /// [gimbal lock]: https://en.wikipedia.org/wiki/Gimbal_lock#Gimbal_lock_in_applied_mathematics
/// [convert]: #defining-rotations-using-euler-angles /// [convert]: #defining-rotations-using-euler-angles
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View file

@ -72,6 +72,8 @@ extern crate serde;
#[cfg(feature = "simd")] #[cfg(feature = "simd")]
extern crate simd; extern crate simd;
extern crate safer_ffi;
// Re-exports // Re-exports
pub use approx::*; pub use approx::*;

View file

@ -33,6 +33,7 @@ use euler::Euler;
use num::{BaseFloat, BaseNum}; use num::{BaseFloat, BaseNum};
use point::{Point2, Point3}; use point::{Point2, Point3};
use quaternion::Quaternion; use quaternion::Quaternion;
use safer_ffi::prelude::*;
use transform::{Transform, Transform2, Transform3}; use transform::{Transform, Transform2, Transform3};
use vector::{Vector2, Vector3, Vector4}; use vector::{Vector2, Vector3, Vector4};
@ -41,7 +42,8 @@ use mint;
/// A 2 x 2, column major matrix /// A 2 x 2, column major matrix
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -54,7 +56,8 @@ pub struct Matrix2<S> {
/// A 3 x 3, column major matrix /// A 3 x 3, column major matrix
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -69,7 +72,8 @@ pub struct Matrix3<S> {
/// A 4 x 4, column major matrix /// A 4 x 4, column major matrix
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View file

@ -27,13 +27,15 @@ use structure::*;
use approx; use approx;
use num::{BaseFloat, BaseNum}; use num::{BaseFloat, BaseNum};
use vector::{Vector1, Vector2, Vector3, Vector4}; use vector::{Vector1, Vector2, Vector3, Vector4};
use safer_ffi::prelude::*;
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
use mint; use mint;
/// A point in 1-dimensional space. /// A point in 1-dimensional space.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(PartialEq, Eq, Copy, Clone, Hash)] #[derive(PartialEq, Eq, Copy, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -43,7 +45,8 @@ pub struct Point1<S> {
/// A point in 2-dimensional space. /// A point in 2-dimensional space.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(PartialEq, Eq, Copy, Clone, Hash)] #[derive(PartialEq, Eq, Copy, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -54,7 +57,8 @@ pub struct Point2<S> {
/// A point in 3-dimensional space. /// A point in 3-dimensional space.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(PartialEq, Eq, Copy, Clone, Hash)] #[derive(PartialEq, Eq, Copy, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View file

@ -33,6 +33,7 @@ use num::{BaseFloat, BaseNum};
use point::Point3; use point::Point3;
use quaternion; use quaternion;
use rotation::{Basis3, Rotation, Rotation3}; use rotation::{Basis3, Rotation, Rotation3};
use safer_ffi::prelude::*;
use vector::Vector3; use vector::Vector3;
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
@ -41,7 +42,8 @@ use mint;
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector /// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
/// form. /// form.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View file

@ -29,13 +29,15 @@ use structure::*;
use angle::Rad; use angle::Rad;
use approx; use approx;
use num::{BaseFloat, BaseNum}; use num::{BaseFloat, BaseNum};
use safer_ffi::prelude::*;
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
use mint; use mint;
/// A 1-dimensional vector. /// A 1-dimensional vector.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(PartialEq, Eq, Copy, Clone, Hash)] #[derive(PartialEq, Eq, Copy, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -46,7 +48,8 @@ pub struct Vector1<S> {
/// A 2-dimensional vector. /// A 2-dimensional vector.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(PartialEq, Eq, Copy, Clone, Hash)] #[derive(PartialEq, Eq, Copy, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -59,7 +62,8 @@ pub struct Vector2<S> {
/// A 3-dimensional vector. /// A 3-dimensional vector.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(PartialEq, Eq, Copy, Clone, Hash)] #[derive(PartialEq, Eq, Copy, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -74,7 +78,8 @@ pub struct Vector3<S> {
/// A 4-dimensional vector. /// A 4-dimensional vector.
/// ///
/// This type is marked as `#[repr(C)]`. /// This type is marked as `#[derive_ReprC] #[repr(C)]`.
#[derive_ReprC]
#[repr(C)] #[repr(C)]
#[derive(PartialEq, Eq, Copy, Clone, Hash)] #[derive(PartialEq, Eq, Copy, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]