Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mod foo {
- pub struct Foo<T> {
- bar: usize,
- inner: T,
- }
- impl<T> Foo<T> {
- pub fn new(inner: T) -> Self {
- Self { bar: 0, inner }
- }
- }
- impl<T> core::ops::Deref for Foo<T> {
- type Target = T;
- fn deref(&self) -> &Self::Target {
- &self.inner
- }
- }
- }
- struct Bar {
- bar: usize,
- }
- fn main() {
- let foo = foo::Foo::new(Bar { bar: 1 });
- println!("{}", foo.bar);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement