Skip to main content

rscad_core/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2pub mod boolean;
3pub mod color;
4pub mod container;
5pub mod degrees;
6#[cfg(feature = "std")]
7pub mod dynamic;
8#[cfg(feature = "std")]
9pub mod feature;
10pub mod geometric;
11#[cfg(feature = "std")]
12pub mod material;
13pub mod objects;
14pub mod operations;
15#[cfg(feature = "std")]
16pub mod sketch;
17pub mod transformations;
18pub use boolean::*;
19pub use color::*;
20pub use container::*;
21pub use degrees::*;
22#[cfg(feature = "std")]
23pub use dynamic::*;
24#[cfg(feature = "std")]
25pub use feature::*;
26pub use geometric::*;
27#[cfg(feature = "std")]
28pub use material::*;
29pub use objects::*;
30pub use operations::*;
31pub use rscad_errors::*;
32#[cfg(feature = "std")]
33pub use sketch::*;
34pub use transformations::*;
35pub(crate) mod prelude_ {
36    pub use super::*;
37}
38pub use glam::*;
39
40#[derive(Clone, Copy, Debug)]
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42#[cfg_attr(feature = "reflect", derive(bevy_reflect::Reflect))]
43pub struct Empty;
44
45pub trait Object {
46    fn name(&self) -> Option<&'static str> {
47        None
48    }
49}
50
51macro_rules! impl_object_tuples {
52    ($($name:ident),+) => {
53        impl<$($name: Object),+> Object for ($($name,)+) {}
54    };
55}
56impl_object_tuples!(A);
57impl_object_tuples!(A, B);
58impl_object_tuples!(A, B, C);
59impl_object_tuples!(A, B, C, D);
60impl_object_tuples!(A, B, C, D, E);
61impl_object_tuples!(A, B, C, D, E, F);
62impl_object_tuples!(A, B, C, D, E, F, G);
63impl_object_tuples!(A, B, C, D, E, F, G, H);
64impl_object_tuples!(A, B, C, D, E, F, G, H, I);
65impl_object_tuples!(A, B, C, D, E, F, G, H, I, J);
66impl_object_tuples!(A, B, C, D, E, F, G, H, I, J, K);
67impl_object_tuples!(A, B, C, D, E, F, G, H, I, J, K, L);
68
69impl Object for () {
70    fn name(&self) -> Option<&'static str> {
71        Some("Unit")
72    }
73}
74impl Object for Empty {
75    fn name(&self) -> Option<&'static str> {
76        Some("Empty")
77    }
78}
79impl<T: Object> Object for Option<T> {
80    fn name(&self) -> Option<&'static str> {
81        self.as_ref().and_then(Object::name)
82    }
83}
84#[cfg(feature = "std")]
85impl<T: Object> Object for Vec<T> {}
86#[cfg(feature = "std")]
87impl<T: Object> Object for Box<T> {}
88impl<T, const N: usize> Object for [T; N] {}
89
90pub trait Number {
91    fn to_f64(self) -> f64;
92}
93
94macro_rules! impl_number {
95    ($($t:ty),*) => {
96        $(impl Number for $t {
97            fn to_f64(self) -> f64 { self.into() }
98        })*
99    };
100}
101
102impl_number!(i8, i16, i32, u8, u16, u32, f32, f64);
103
104impl Number for i64 {
105    fn to_f64(self) -> f64 {
106        self as f64
107    }
108}
109
110impl Number for u64 {
111    fn to_f64(self) -> f64 {
112        self as f64
113    }
114}
115
116impl Number for usize {
117    fn to_f64(self) -> f64 {
118        self as f64
119    }
120}
121
122impl Number for isize {
123    fn to_f64(self) -> f64 {
124        self as f64
125    }
126}