1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
use crate::sub_value::ValueTinyInt;
use std::ops::{Mul, MulAssign};
impl<T> MulAssign<T> for ValueTinyInt
where
T: Into<ValueTinyInt>,
{
fn mul_assign(&mut self, rhs: T) {
let rhs: Self = rhs.into();
match &mut self.0 {
Some(v) => match rhs.0 {
Some(o) => *v *= o,
None => *v *= 0,
},
None => match rhs.0 {
Some(o) => self.0 = Some(0 * o),
None => (),
},
}
}
}
/// # Examples
///
/// ```
/// use arel::prelude::*;
/// use arel::value::sub_value::ValueTinyInt;
/// let v1: ValueTinyInt = 1.into();
/// assert_eq!(v1 * 2, ValueTinyInt(Some(2)));
///
/// let v1: ValueTinyInt = None::<i8>.into();
/// assert_eq!(v1 * 2, ValueTinyInt(Some(0)));
///```
impl<T> Mul<T> for ValueTinyInt
where
T: Into<ValueTinyInt>,
{
type Output = Self;
fn mul(mut self, rhs: T) -> Self::Output {
let rhs: Self = rhs.into();
self *= rhs;
self
}
}