Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1dd7ce0b authored by Rahul Arya's avatar Rahul Arya
Browse files

[Connection Manager] Add new_cyclic to SharedBox

Bug: 272572974
Test: all existing
Change-Id: Ida0b02181bef576a63b498750904fd2f54334bab
parent 84c60740
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -23,6 +23,12 @@ impl<T> SharedBox<T> {
        Self(t.into())
    }

    /// Constructs a new SharedBox<T> while giving you a WeakBox<T> to the allocation,
    /// to allow you to construct a T which holds a weak pointer to itself.
    pub fn new_cyclic(f: impl FnOnce(WeakBox<T>) -> T) -> Self {
        Self(Rc::new_cyclic(|weak| f(WeakBox(weak.clone()))))
    }

    /// Produce a weak reference to the contents
    pub fn downgrade(&self) -> WeakBox<T> {
        WeakBox(Rc::downgrade(&self.0))