Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- struct A<'a>
- {
- pub b: &'a mut B,
- }
- impl<'a> A<'a>
- {
- fn new(b: &'a mut B) -> A<'a>
- {
- A
- {
- b: b,
- }
- }
- fn foo(self) -> A<'a>
- {
- &self.b.bar();
- self
- }
- }
- #[derive(Debug)]
- struct B
- {
- b1: String,
- }
- impl B
- {
- fn new() -> B
- {
- B
- {
- b1: String::from(""),
- }
- }
- fn bar(&mut self)
- {
- self.b1 = String::from("Foo Bar");
- }
- }
- fn main()
- {
- let mut b = B::new();
- let a = A::new(&mut b); // Trying to avoid making a mutable.
- let a = a.foo();
- println!("{:?}", &a);
- }
Add Comment
Please, Sign In to add comment