Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 24, 2020 16:19

Revisions

  1. rust-play created this gist Jan 24, 2020.
    26 changes: 26 additions & 0 deletions playground.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    struct Inner {
    a: A,
    }

    impl Inner {
    fn fun(&mut self) {
    self.a.something();
    }
    fn fun2(&mut self, outer: &Arc<Outer>) {
    self.a.something2(outer.b);
    }
    }

    struct Outer {
    b: B,
    inner: Mutex<Inner>,
    }

    impl Outer {
    fn mainfun(self: Arc<Self>) {
    let mut inner = self.inner.lock();
    // do something with held locks
    inner.fun2(&self);
    // do something more
    }
    }