so I've been thinking about some rust syntax for some cell types, and I wanted to see what you guys think.
I am not 100% sold into this design, but I hope to at least have a discussion of possible designs for this, as I think cell.set(cell.get() + 1) doesn't feel and look as good as the typical *num += 1
Now, for the design, we could have something like
impl ShrAddAssign<T: Copy + Add<T>> for Cell<T>{
fn shr_add_assign(&self, input: T){
self.set(self.get() + input)
}
}
impl ShrAddAssign<T: Copy + AddAssign<T>> for RefCell<T>{
fn shr_add_assign(&self, input: T){
*self.borrow_mut() += input;
}
}
impl ShrAssign<T: Copy> for Cell<T>{
fn shr_assign(&self, input: T){
self.set(input)
}
}
impl ShrAssign<T: Copy> for RefCell<T>{
fn shr_assign(&self, input: T){
*self.borrow_mut() = input;
}
}
impl ShrInner<T: Copy> for Cell<T>{
fn shr_inner(&self) -> T{
self.get()
}
}
impl ShrInner<T: Copy> for RefCell<T>{
fn shr_inner(&self) -> T{
*self.borrow()
}
}
and then u can do
let cell : &Cell<i32>= &Cell::new(4);
*cell := 5; // ShrAssign
*cell :+= 5; // ShrAddAssign
let number : i32 = ^cell; // ShrInner.
I've also thought, that maybe for something like ShrAddAssign, it can use the same += syntax instead of :+= and then there would be a blanket implementation that look like this:
impl<T: ShrAddAssign<U>, U> AddAssign<U> for T{}