feat: enable addassign for usestate

This commit is contained in:
Jonathan Kelley committed 2022-03-05 17:07:34 -05:00
1 parent e4fac574ed
commit a4ab2d9de0
3 files changed
+32 -11

No files matched your search

+25 -1
View File
@@ -4,7 +4,7 @@ use dioxus_core::prelude::*;
use std::{
cell::{RefCell, RefMut},
fmt::{Debug, Display},
ops::Not,
ops::{Add, Div, Mul, Not, Sub},
rc::Rc,
sync::Arc,
};
@@ -390,6 +390,30 @@ impl<T: std::ops::Mul + Copy> std::ops::Mul<T> for &UseState<T> {
}
}
impl<T: Add<Output = T> + Copy> std::ops::AddAssign<T> for &UseState<T> {
fn add_assign(&mut self, rhs: T) {
self.set((*self.current()) + rhs);
}
}
impl<T: Sub<Output = T> + Copy> std::ops::SubAssign<T> for &UseState<T> {
fn sub_assign(&mut self, rhs: T) {
self.set((*self.current()) - rhs);
}
}
impl<T: Mul<Output = T> + Copy> std::ops::MulAssign<T> for &UseState<T> {
fn mul_assign(&mut self, rhs: T) {
self.set((*self.current()) * rhs);
}
}
impl<T: Div<Output = T> + Copy> std::ops::DivAssign<T> for &UseState<T> {
fn div_assign(&mut self, rhs: T) {
self.set((*self.current()) / rhs);
}
}
#[test]
fn api_makes_sense() {
#[allow(unused)]