#![cfg_attr(not(feature = "std"), doc = "```ignore")]
#![cfg_attr(feature = "std", doc = "```")]
use crate::{AsIntermediate, Intermediate, Size};
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
impl Add<Size> for Size {
type Output = Size;
fn add(self, other: Size) -> Self::Output {
Size::from_bytes(self.bytes() + other.bytes())
}
}
impl Add<Size> for &Size {
type Output = Size;
fn add(self, other: Size) -> Self::Output {
Size::from_bytes(self.bytes() + other.bytes())
}
}
impl Add<&Size> for Size {
type Output = Size;
fn add(self, other: &Size) -> Self::Output {
Size::from_bytes(self.bytes() + other.bytes())
}
}
impl Add<&Size> for &Size {
type Output = Size;
fn add(self, other: &Size) -> Self::Output {
Size::from_bytes(self.bytes() + other.bytes())
}
}
impl Sub<Size> for Size {
type Output = Size;
fn sub(self, other: Size) -> Self::Output {
Size::from_bytes(self.bytes() - other.bytes())
}
}
impl Sub<Size> for &Size {
type Output = Size;
fn sub(self, other: Size) -> Self::Output {
Size::from_bytes(self.bytes() - other.bytes())
}
}
impl Sub<&Size> for Size {
type Output = Size;
fn sub(self, other: &Size) -> Self::Output {
Size::from_bytes(self.bytes() - other.bytes())
}
}
impl Sub<&Size> for &Size {
type Output = Size;
fn sub(self, other: &Size) -> Self::Output {
Size::from_bytes(self.bytes() - other.bytes())
}
}
impl<T> Mul<T> for Size
where
T: AsIntermediate,
{
type Output = Size;
fn mul(self, other: T) -> Self::Output {
Size::from_bytes((self.bytes() as Intermediate * other.as_()) as i64)
}
}
impl<T> Mul<T> for &Size
where
T: AsIntermediate,
{
type Output = Size;
fn mul(self, other: T) -> Self::Output {
Size::from_bytes((self.bytes() as Intermediate * other.as_()) as i64)
}
}
macro_rules! impl_mul {
($type:ty) => {
impl Mul<Size> for $type {
type Output = Size;
fn mul(self, other: Size) -> Self::Output {
Size::from_bytes((self.as_() * other.bytes() as Intermediate) as i64)
}
}
impl Mul<&Size> for $type {
type Output = Size;
fn mul(self, other: &Size) -> Self::Output {
Size::from_bytes((self.as_() * other.bytes() as Intermediate) as i64)
}
}
};
}
impl_mul!(i64);
#[cfg(feature = "std")]
impl_mul!(f64);
impl<T> Div<T> for Size
where
T: AsIntermediate,
{
type Output = Size;
fn div(self, other: T) -> Self::Output {
Size::from_bytes((self.bytes() as Intermediate / other.as_()) as i64)
}
}
impl<T> Div<T> for &Size
where
T: AsIntermediate,
{
type Output = Size;
fn div(self, other: T) -> Self::Output {
Size::from_bytes((self.bytes() as Intermediate / other.as_()) as i64)
}
}
impl AddAssign<Size> for Size {
fn add_assign(&mut self, other: Size) {
*self = *self + other;
}
}
impl AddAssign<&Size> for Size {
fn add_assign(&mut self, other: &Size) {
*self = *self + other;
}
}
impl SubAssign<Size> for Size {
fn sub_assign(&mut self, other: Size) {
*self = *self - other;
}
}
impl SubAssign<&Size> for Size {
fn sub_assign(&mut self, other: &Size) {
*self = *self - other;
}
}
impl<T> MulAssign<T> for Size
where
T: AsIntermediate,
{
fn mul_assign(&mut self, other: T) {
*self = *self * other;
}
}
impl<T> DivAssign<T> for Size
where
T: AsIntermediate,
{
fn div_assign(&mut self, other: T) {
*self = *self / other;
}
}