Skip to main content

pedalkernel/compiler/components/
mod.rs

1//! Individual component structs implementing the `Component` trait.
2//!
3//! Each struct holds the data for one circuit component type and implements
4//! the full `Component` trait.
5
6mod active_ics;
7mod delay;
8mod diodes;
9mod modulation;
10mod passives;
11mod switches;
12mod tape_head;
13mod transformer;
14mod transistors;
15mod tubes;
16
17pub use active_ics::*;
18pub use delay::*;
19pub use diodes::*;
20pub use modulation::*;
21pub use passives::*;
22pub use switches::*;
23pub use tape_head::*;
24pub use transformer::*;
25pub use transistors::*;
26pub use tubes::*;
27
28/// Macro to implement the three trait-object support methods (clone_box, as_any, dyn_eq)
29/// that every `Component` implementor needs. Requires the struct to derive Clone + PartialEq.
30macro_rules! impl_component_dyn {
31    () => {
32        fn clone_box(&self) -> Box<dyn crate::compiler::component::Component> {
33            Box::new(self.clone())
34        }
35        fn as_any(&self) -> &dyn std::any::Any {
36            self
37        }
38        fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
39            self
40        }
41        fn dyn_eq(&self, other: &dyn crate::compiler::component::Component) -> bool {
42            other
43                .as_any()
44                .downcast_ref::<Self>()
45                .map_or(false, |o| self == o)
46        }
47    };
48}
49pub(crate) use impl_component_dyn;