refactor!(argus-core): remove unnecessary traits and Copy constraints

This commit is contained in:
Anand Balakrishnan 2023-08-29 18:16:10 -07:00
parent 86cef692dc
commit 28a79cb88c
No known key found for this signature in database
9 changed files with 255 additions and 271 deletions

View file

@ -1,12 +1,29 @@
use super::interpolation::Linear;
use crate::signals::utils::{apply1, apply2};
use crate::signals::Signal;
impl core::ops::Not for Signal<bool> {
type Output = Signal<bool>;
fn not(self) -> Self::Output {
use Signal::*;
match self {
Empty => self,
Constant { value } => Signal::constant(!value),
signal => signal.into_iter().map(|(&t, v)| (t, !v)).collect(),
}
}
}
impl core::ops::Not for &Signal<bool> {
type Output = Signal<bool>;
fn not(self) -> Self::Output {
apply1(self, |v| !v)
use Signal::*;
match self {
Empty => Empty,
Constant { value } => Signal::constant(!value),
signal => signal.into_iter().map(|(&t, &v)| (t, !v)).collect(),
}
}
}
@ -18,7 +35,7 @@ impl Signal<bool> {
///
/// See [`Signal::sync_with_intersection`].
pub fn and(&self, other: &Self) -> Self {
apply2::<_, _, _, Linear>(self, other, |lhs, rhs| lhs && rhs)
self.binary_op::<_, _, Linear>(other, |lhs, rhs| *lhs && *rhs)
}
/// Apply logical disjunction for each sample across the two signals.
@ -28,22 +45,38 @@ impl Signal<bool> {
///
/// See [`Signal::sync_with_intersection`].
pub fn or(&self, other: &Self) -> Self {
apply2::<_, _, _, Linear>(self, other, |lhs, rhs| lhs || rhs)
self.binary_op::<_, _, Linear>(other, |lhs, rhs| *lhs || *rhs)
}
}
impl core::ops::BitAnd<Self> for &Signal<bool> {
impl core::ops::BitAnd<&Signal<bool>> for Signal<bool> {
type Output = Signal<bool>;
fn bitand(self, other: Self) -> Self::Output {
fn bitand(self, other: &Signal<bool>) -> Self::Output {
self.and(other)
}
}
impl core::ops::BitOr<Self> for &Signal<bool> {
impl core::ops::BitAnd<&Signal<bool>> for &Signal<bool> {
type Output = Signal<bool>;
fn bitor(self, other: Self) -> Self::Output {
fn bitand(self, other: &Signal<bool>) -> Self::Output {
self.and(other)
}
}
impl core::ops::BitOr<&Signal<bool>> for Signal<bool> {
type Output = Signal<bool>;
fn bitor(self, other: &Signal<bool>) -> Self::Output {
self.or(other)
}
}
impl core::ops::BitOr<&Signal<bool>> for &Signal<bool> {
type Output = Signal<bool>;
fn bitor(self, other: &Signal<bool>) -> Self::Output {
self.or(other)
}
}