fxfs/drop_event.rs
1// Copyright 2022 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
5use event_listener::Event;
6use std::ops::Deref;
7
8/// Same as Event but notifies when dropped.
9pub struct DropEvent(Event);
10
11impl Drop for DropEvent {
12 fn drop(&mut self) {
13 self.0.notify(usize::MAX);
14 }
15}
16
17impl Deref for DropEvent {
18 type Target = Event;
19
20 fn deref(&self) -> &Self::Target {
21 &self.0
22 }
23}
24
25impl DropEvent {
26 pub fn new() -> Self {
27 Self(Event::new())
28 }
29}