For example:
use std::ops::{Deref, DerefMut};
struct Foo {}
impl Foo {
pub fn foo1() {}
pub fn foo2(&self) {}
}
pub struct Bar(Foo);
impl Deref for Bar {
type Target = Foo;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for Bar {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
fn main() {
Bar::foo1(); // won't compile
}
I'm kind of knowing why this happens and how Deref
trait works, but I still wondered if I can "hide" the Foo
, and calling all it's associated function from Bar
.