vigil/
lib.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5pub trait DropWatch<T: ?Sized> {
6    /// Adds a function to be called just before this item is dropped.
7    /// The function takes a reference to the item being dropped to avoid collision.
8    /// /// # Example
9    ///
10    /// ```
11    /// use vigil::DropWatch;
12    ///
13    /// let x = Vigil::new(5);
14    ///
15    /// DropWatch::watch(&v, |it| print!("{} about to be dropped!", it));
16    /// ```
17    fn watch(this: &Self, drop_fn: impl FnOnce(&T) + 'static);
18
19    /// Makes a Dropped struct, which is a Future that completes just before the item is dropped.
20    fn dropped(this: &Self) -> Dropped {
21        Dropped::new(this)
22    }
23}
24
25pub mod vigil;
26pub use vigil::Vigil;
27
28pub mod dropped;
29pub use dropped::Dropped;