reda_sp/model/components/
basic.rs

1use derive_builder::Builder;
2use reda_unit::{Capacitance, Inductance, Resistance};
3
4use crate::ToSpice;
5
6#[derive(Debug, Clone, Builder)]
7#[builder(setter(strip_option, into))]
8pub struct Resistor {
9    pub name: String,
10    pub node_pos: String,
11    pub node_neg: String,
12    pub resistance: Resistance,
13}
14
15#[derive(Debug, Clone, Builder)]
16#[builder(setter(strip_option, into))]
17pub struct Capacitor {
18    pub name: String,
19    pub node_pos: String,
20    pub node_neg: String,
21    pub capacitance: Capacitance,
22}
23
24#[derive(Debug, Clone, Builder)]
25#[builder(setter(strip_option, into))]
26pub struct Inductor {
27    pub name: String,
28    pub node_pos: String,
29    pub node_neg: String,
30    pub inductance: Inductance,
31}
32
33impl ToSpice for Resistor {
34    fn to_spice(&self) -> String {
35        format!(
36            "R{} {} {} {}",
37            self.name,
38            self.node_pos,
39            self.node_neg,
40            self.resistance.value()
41        )
42    }
43}
44
45impl ToSpice for Capacitor {
46    fn to_spice(&self) -> String {
47        format!(
48            "C{} {} {} {}",
49            self.name,
50            self.node_pos,
51            self.node_neg,
52            self.capacitance
53        )
54    }
55}
56
57impl ToSpice for Inductor {
58    fn to_spice(&self) -> String {
59        format!(
60            "L{} {} {} {}",
61            self.name,
62            self.node_pos,
63            self.node_neg,
64            self.inductance
65        )
66    }
67}