eng_units/units/
luminous_intensity_unit.rs

1// eng-units - engineering unit conversion and calculation library
2// Copyright (C) 2023 Frank Pereny
3
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17use crate::units::AmountOfSubstanceUnit;
18use crate::units::ElectricCurrentUnit;
19use crate::units::IsEngUnitType;
20use crate::units::LengthUnit;
21use crate::units::MassUnit;
22use crate::units::TemperatureDeltaUnit;
23use crate::units::TimeUnit;
24
25#[derive(Copy, Clone, Debug, PartialEq)]
26pub enum LuminousIntensityUnit {
27    Candela,
28    None,
29}
30
31impl LuminousIntensityUnit {
32    pub fn conversion_factor(from: &LuminousIntensityUnit, to: &LuminousIntensityUnit) -> f64 {
33        match from {
34            Self::Candela => match to {
35                Self::Candela => 1.0,
36                Self::None => 1.0,
37            },
38            Self::None => 1.0,
39        }
40    }
41
42    pub fn to_string(&self) -> &'static str {
43        match self {
44            LuminousIntensityUnit::Candela => "cd",
45            LuminousIntensityUnit::None => "",
46        }
47    }
48}
49
50impl<
51        T: IsEngUnitType
52            + Into<AmountOfSubstanceUnit>
53            + Into<ElectricCurrentUnit>
54            + Into<LengthUnit>
55            + Into<LuminousIntensityUnit>
56            + Into<MassUnit>
57            + Into<TemperatureDeltaUnit>
58            + Into<TimeUnit>,
59    > From<&T> for LuminousIntensityUnit
60{
61    fn from(value: &T) -> Self {
62        if T::is_amount_unit() {
63            value.into()
64        } else {
65            Self::None
66        }
67    }
68}
69impl IsEngUnitType for LuminousIntensityUnit {
70    fn is_luminous_unit() -> bool {
71        true
72    }
73}
74impl From<AmountOfSubstanceUnit> for LuminousIntensityUnit {
75    fn from(_: AmountOfSubstanceUnit) -> Self {
76        LuminousIntensityUnit::None
77    }
78}
79impl From<ElectricCurrentUnit> for LuminousIntensityUnit {
80    fn from(_: ElectricCurrentUnit) -> Self {
81        LuminousIntensityUnit::None
82    }
83}
84impl From<LengthUnit> for LuminousIntensityUnit {
85    fn from(_: LengthUnit) -> Self {
86        LuminousIntensityUnit::None
87    }
88}
89impl From<MassUnit> for LuminousIntensityUnit {
90    fn from(_: MassUnit) -> Self {
91        LuminousIntensityUnit::None
92    }
93}
94impl From<TemperatureDeltaUnit> for LuminousIntensityUnit {
95    fn from(_: TemperatureDeltaUnit) -> Self {
96        LuminousIntensityUnit::None
97    }
98}
99impl From<TimeUnit> for LuminousIntensityUnit {
100    fn from(_: TimeUnit) -> Self {
101        LuminousIntensityUnit::None
102    }
103}