diff --git a/Cargo.toml b/Cargo.toml index cb9a73ce..731eed64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ num-traits = "0.2" rand = { version = "0.7", features = ["small_rng"], optional = true } serde = { version = "1.0", features = ["serde_derive"], optional = true } simd = { version = "0.2", optional = true } # works only in rust toolchain up to 1.32 +schemars = { version = "0.7", optional = true } [dev-dependencies] # glium = "0.23" # causes problems with nightly-2019-01-01 needed for testing "simd" diff --git a/src/angle.rs b/src/angle.rs index a99598e6..b9ff740b 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -38,6 +38,7 @@ use num::BaseFloat; #[repr(C)] #[derive(Copy, Clone, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Rad(pub S); /// An angle, in degrees. @@ -46,6 +47,7 @@ pub struct Rad(pub S); #[repr(C)] #[derive(Copy, Clone, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Deg(pub S); impl From> for Deg diff --git a/src/euler.rs b/src/euler.rs index 1e66bb20..3e8bc1bb 100644 --- a/src/euler.rs +++ b/src/euler.rs @@ -81,6 +81,7 @@ use quaternion::Quaternion; #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Euler { /// The angle to apply around the _x_ axis. Also known at the _pitch_. pub x: A, diff --git a/src/lib.rs b/src/lib.rs index b9642cbb..b55a3eb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,6 +69,10 @@ extern crate serde; #[cfg(feature = "simd")] extern crate simd; +#[cfg(feature = "schemars")] +#[macro_use] +extern crate schemars; + // Re-exports pub use approx::*; diff --git a/src/matrix.rs b/src/matrix.rs index ea0e9de7..a50af7a5 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -45,6 +45,7 @@ use mint; #[repr(C)] #[derive(Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Matrix2 { /// The first column of the matrix. pub x: Vector2, @@ -58,6 +59,7 @@ pub struct Matrix2 { #[repr(C)] #[derive(Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Matrix3 { /// The first column of the matrix. pub x: Vector3, @@ -73,6 +75,7 @@ pub struct Matrix3 { #[repr(C)] #[derive(Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Matrix4 { /// The first column of the matrix. pub x: Vector4, diff --git a/src/point.rs b/src/point.rs index faf2a6db..cfb067e6 100644 --- a/src/point.rs +++ b/src/point.rs @@ -37,6 +37,7 @@ use mint; #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Point1 { pub x: S, } @@ -47,6 +48,7 @@ pub struct Point1 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Point2 { pub x: S, pub y: S, @@ -58,6 +60,7 @@ pub struct Point2 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Point3 { pub x: S, pub y: S, diff --git a/src/projection.rs b/src/projection.rs index 8ba3dc0a..e7c9d124 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -80,6 +80,7 @@ pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct PerspectiveFov { pub fovy: Rad, pub aspect: S, @@ -176,6 +177,7 @@ impl From> for Matrix4 { /// A perspective projection with arbitrary left/right/bottom/top distances #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Perspective { pub left: S, pub right: S, @@ -241,6 +243,7 @@ impl From> for Matrix4 { /// An orthographic projection with arbitrary left/right/bottom/top distances #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Ortho { pub left: S, pub right: S, diff --git a/src/quaternion.rs b/src/quaternion.rs index 6a48b522..dc0f9ac5 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -45,6 +45,7 @@ use mint; #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Quaternion { /// The scalar part of the quaternion. pub s: S, diff --git a/src/rotation.rs b/src/rotation.rs index e7fa1f6f..26a5f09b 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -164,6 +164,7 @@ pub trait Rotation3: /// ``` #[derive(PartialEq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Basis2 { mat: Matrix2, } @@ -310,6 +311,7 @@ impl fmt::Debug for Basis2 { /// been restricted to a subset of those implemented on `Matrix3`. #[derive(PartialEq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Basis3 { mat: Matrix3, } diff --git a/src/vector.rs b/src/vector.rs index adcc5816..40ae306b 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -39,6 +39,7 @@ use mint; #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Vector1 { /// The x component of the vector. pub x: S, @@ -50,6 +51,7 @@ pub struct Vector1 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Vector2 { /// The x component of the vector. pub x: S, @@ -63,6 +65,7 @@ pub struct Vector2 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Vector3 { /// The x component of the vector. pub x: S, @@ -78,6 +81,7 @@ pub struct Vector3 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Vector4 { /// The x component of the vector. pub x: S,