ac_power/number.rs
1// Copyright 2023 Enphase Energy, Inc and Universal Interoperability for
2// Grid-Forming Inverters (UNIFI) Consortium.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16/*!
17Definition of the numeric trait required for the reference frames elements
18*/
19
20use crate::newtypes::{Current, Power, Voltage};
21use crate::trig::{Cos, Sin};
22use core::fmt::Debug;
23use core::ops::{Add, AddAssign, Mul, Neg, Sub};
24
25/// Generic type with a trait bound for acceptable number types for use with reference frame structures
26pub trait Num:
27 Add<Output = Self>
28 + AddAssign<Self>
29 + Sub<Output = Self>
30 + Mul<f32, Output = Self>
31 + Mul<Cos, Output = Self>
32 + Mul<Sin, Output = Self>
33 + Neg<Output = Self>
34 + From<f32>
35 + Into<f32>
36 + Copy
37 + Debug
38{
39}
40
41impl Num for f32 {}
42impl Num for Voltage {}
43impl Num for Current {}
44impl Num for Power {}