Any advantage the with construct would provide over the code bellow?
fn main(){
let mut val=with(Rectangle::default(),|a|{
a.x=100;
a.w=200;
});
with_mut(&mut val,|a|{
a.h=a.w;
a.w*=200;
});
assert_eq!(
val,
Rectangle{
x:100,
y:0,
w:40000,
h:200,
}
);
}
pub fn with<T>(mut this:T,f:impl FnOnce(&mut T))->T{
f(&mut this);
this
}
pub fn with_mut<T,U>(this:&mut T,f:impl FnOnce(&mut T)->U)->U{
f(this)
}
pub fn with_ref<T,U>(this:&T,f:impl FnOnce(&T)->U)->U{
f(this)
}
#[derive(Debug,Default,PartialEq)]
struct Rectangle{
x:u32,
y:u32,
w:u32,
h:u32,
}