Skip to content

Commit f8a73e0

Browse files
committed
Extend specta::Type implementations for glam feature to include all types listen in the [Glam Documentation](https://docs.rs/glam/latest/glam/)
1 parent e455aae commit f8a73e0

File tree

1 file changed

+97
-73
lines changed

1 file changed

+97
-73
lines changed

specta/src/type/legacy_impls.rs

Lines changed: 97 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -327,80 +327,104 @@ const _: () = {
327327

328328
#[cfg(feature = "glam")]
329329
const _: () = {
330-
#[derive(Type)]
331-
#[specta(remote = glam::DVec2, crate = crate, export = false)]
332-
#[allow(dead_code)]
333-
struct DVec2([f64; 2]);
334-
335-
#[derive(Type)]
336-
#[specta(remote = glam::IVec2, crate = crate, export = false)]
337-
#[allow(dead_code)]
338-
struct IVec2([i32; 2]);
339-
340-
#[derive(Type)]
341-
#[specta(remote = glam::DMat2, crate = crate, export = false)]
342-
#[allow(dead_code)]
343-
struct DMat2([f64; 4]);
344-
345-
#[derive(Type)]
346-
#[specta(remote = glam::DAffine2, crate = crate, export = false)]
347-
#[allow(dead_code)]
348-
struct DAffine2([f64; 6]);
349-
350-
#[derive(Type)]
351-
#[specta(remote = glam::Vec2, crate = crate, export = false)]
352-
#[allow(dead_code)]
353-
struct Vec2([f32; 2]);
354-
355-
#[derive(Type)]
356-
#[specta(remote = glam::Vec3, crate = crate, export = false)]
357-
#[allow(dead_code)]
358-
struct Vec3([f32; 3]);
359-
360-
#[derive(Type)]
361-
#[specta(remote = glam::Vec3A, crate = crate, export = false)]
362-
#[allow(dead_code)]
363-
struct Vec3A([f32; 3]);
364-
365-
#[derive(Type)]
366-
#[specta(remote = glam::Vec4, crate = crate, export = false)]
367-
#[allow(dead_code)]
368-
struct Vec4([f32; 4]);
369-
370-
#[derive(Type)]
371-
#[specta(remote = glam::Mat2, crate = crate, export = false)]
372-
#[allow(dead_code)]
373-
struct Mat2([f32; 4]);
374-
375-
#[derive(Type)]
376-
#[specta(remote = glam::Mat3, crate = crate, export = false)]
377-
#[allow(dead_code)]
378-
struct Mat3([f32; 9]);
379-
380-
#[derive(Type)]
381-
#[specta(remote = glam::Mat3A, crate = crate, export = false)]
382-
#[allow(dead_code)]
383-
struct Mat3A([f32; 9]);
384-
385-
#[derive(Type)]
386-
#[specta(remote = glam::Mat4, crate = crate, export = false)]
387-
#[allow(dead_code)]
388-
struct Mat4([f32; 16]);
389-
390-
#[derive(Type)]
391-
#[specta(remote = glam::Quat, crate = crate, export = false)]
392-
#[allow(dead_code)]
393-
struct Quat([f32; 4]);
394-
395-
#[derive(Type)]
396-
#[specta(remote = glam::Affine2, crate = crate, export = false)]
397-
#[allow(dead_code)]
398-
struct Affine2([f32; 6]);
330+
macro_rules! implement_specta_type_for_glam_type {
331+
(
332+
$name: ident as $representation: ty
333+
) => {
334+
#[derive(Type)]
335+
#[specta(remote = glam::$name, crate = crate, export = false)]
336+
#[allow(dead_code)]
337+
struct $name($representation);
338+
};
339+
}
399340

400-
#[derive(Type)]
401-
#[specta(remote = glam::Affine3A, crate = crate, export = false)]
402-
#[allow(dead_code)]
403-
struct Affine3A([f32; 12]);
341+
// Implementations for https://docs.rs/glam/latest/glam/f32/index.html
342+
// Affines
343+
implement_specta_type_for_glam_type!(Affine2 as [f32; 6]);
344+
implement_specta_type_for_glam_type!(Affine3A as [f32; 12]);
345+
346+
// Matrices
347+
implement_specta_type_for_glam_type!(Mat2 as [f32; 4]);
348+
implement_specta_type_for_glam_type!(Mat3 as [f32; 9]);
349+
implement_specta_type_for_glam_type!(Mat3A as [f32; 9]);
350+
implement_specta_type_for_glam_type!(Mat4 as [f32; 16]);
351+
352+
// Quaternions
353+
implement_specta_type_for_glam_type!(Quat as [f32; 4]);
354+
355+
// Vectors
356+
implement_specta_type_for_glam_type!(Vec2 as [f32; 2]);
357+
implement_specta_type_for_glam_type!(Vec3 as [f32; 3]);
358+
implement_specta_type_for_glam_type!(Vec3A as [f32; 3]);
359+
implement_specta_type_for_glam_type!(Vec4 as [f32; 4]);
360+
361+
// Implementations for https://docs.rs/glam/latest/glam/f64/index.html
362+
// Affines
363+
implement_specta_type_for_glam_type!(DAffine2 as [f64; 6]);
364+
implement_specta_type_for_glam_type!(DAffine3 as [f64; 12]);
365+
366+
// Matrices
367+
implement_specta_type_for_glam_type!(DMat2 as [f64; 4]);
368+
implement_specta_type_for_glam_type!(DMat3 as [f64; 9]);
369+
implement_specta_type_for_glam_type!(DMat4 as [f64; 16]);
370+
371+
// Quaternions
372+
implement_specta_type_for_glam_type!(DQuat as [f64; 4]);
373+
374+
// Vectors
375+
implement_specta_type_for_glam_type!(DVec2 as [f64; 2]);
376+
implement_specta_type_for_glam_type!(DVec3 as [f64; 3]);
377+
implement_specta_type_for_glam_type!(DVec4 as [f64; 4]);
378+
379+
// Implementations for https://docs.rs/glam/latest/glam/i8/index.html
380+
implement_specta_type_for_glam_type!(I8Vec2 as [i8; 2]);
381+
implement_specta_type_for_glam_type!(I8Vec3 as [i8; 3]);
382+
implement_specta_type_for_glam_type!(I8Vec4 as [i8; 4]);
383+
384+
// Implementations for https://docs.rs/glam/latest/glam/u8/index.html
385+
implement_specta_type_for_glam_type!(U8Vec2 as [u8; 2]);
386+
implement_specta_type_for_glam_type!(U8Vec3 as [u8; 3]);
387+
implement_specta_type_for_glam_type!(U8Vec4 as [u8; 4]);
388+
389+
// Implementations for https://docs.rs/glam/latest/glam/i16/index.html
390+
implement_specta_type_for_glam_type!(I16Vec2 as [i16; 2]);
391+
implement_specta_type_for_glam_type!(I16Vec3 as [i16; 3]);
392+
implement_specta_type_for_glam_type!(I16Vec4 as [i16; 4]);
393+
394+
// Implementations for https://docs.rs/glam/latest/glam/u16/index.html
395+
implement_specta_type_for_glam_type!(U16Vec2 as [u16; 2]);
396+
implement_specta_type_for_glam_type!(U16Vec3 as [u16; 3]);
397+
implement_specta_type_for_glam_type!(U16Vec4 as [u16; 4]);
398+
399+
// Implementations for https://docs.rs/glam/latest/glam/i32/index.html
400+
implement_specta_type_for_glam_type!(IVec2 as [i32; 2]);
401+
implement_specta_type_for_glam_type!(IVec3 as [i32; 3]);
402+
implement_specta_type_for_glam_type!(IVec4 as [i32; 4]);
403+
404+
// Implementations for https://docs.rs/glam/latest/glam/u32/index.html
405+
implement_specta_type_for_glam_type!(UVec2 as [u32; 2]);
406+
implement_specta_type_for_glam_type!(UVec3 as [u32; 3]);
407+
implement_specta_type_for_glam_type!(UVec4 as [u32; 4]);
408+
409+
// Implementation for https://docs.rs/glam/latest/glam/i64/index.html
410+
implement_specta_type_for_glam_type!(I64Vec2 as [i64; 2]);
411+
implement_specta_type_for_glam_type!(I64Vec3 as [i64; 3]);
412+
implement_specta_type_for_glam_type!(I64Vec4 as [i64; 4]);
413+
414+
// Implementation for https://docs.rs/glam/latest/glam/u64/index.html
415+
implement_specta_type_for_glam_type!(U64Vec2 as [u64; 2]);
416+
implement_specta_type_for_glam_type!(U64Vec3 as [u64; 3]);
417+
implement_specta_type_for_glam_type!(U64Vec4 as [u64; 4]);
418+
419+
// implementation for https://docs.rs/glam/latest/glam/usize/index.html
420+
implement_specta_type_for_glam_type!(USizeVec2 as [usize; 2]);
421+
implement_specta_type_for_glam_type!(USizeVec3 as [usize; 3]);
422+
implement_specta_type_for_glam_type!(USizeVec4 as [usize; 4]);
423+
424+
// Implementation for https://docs.rs/glam/latest/glam/bool/index.html
425+
implement_specta_type_for_glam_type!(BVec2 as [bool; 2]);
426+
implement_specta_type_for_glam_type!(BVec3 as [bool; 3]);
427+
implement_specta_type_for_glam_type!(BVec4 as [bool; 4]);
404428
};
405429

406430
#[cfg(feature = "url")]

0 commit comments

Comments
 (0)