Here what I want to achieve:
trait Foo {
fn readonly(&self) -> i32;
fn modify(&mut self, val: i32);
}
struct FooWrapper<'a> {
foo: &'a Foo,
}
impl<'a> FooWrapper<'a> {
fn readonly(&self) -> i32 {
self.foo.readonly()
}
fn modify(&mut self, val: i32) {
self.foo.modify(val);//!!!
}
}
As input I got &Foo
and &mut Foo
, like:
fn func(a: &Foo, b: &mut Foo)
.
I want then wrap them inside FooWraper
, and use it's methods
to work with Foo
.
But as you see compiler not allow code marked with //!!!
.
Any way to fix this without code duplication like:
struct FooWrapper<'a> {
foo: &'a Foo,
}
struct FooWrapperMut<'a> {
foo: &'a mut Foo,
}
impl<'a> FooWrapper<'a>..
impl<'a> FooWrapperMut<'a>..
?