1 // Copyright 2017 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 
5 //! Type-safe bindings for Zircon event objects.
6 
7 use {AsHandleRef, Cookied, HandleBased, Handle, HandleRef, Status};
8 use {sys, ok};
9 
10 /// An object representing a Zircon
11 /// [event object](https://fuchsia.googlesource.com/zircon/+/master/docs/objects/event.md).
12 ///
13 /// As essentially a subtype of `Handle`, it can be freely interconverted.
14 #[derive(Debug, Eq, PartialEq)]
15 pub struct Event(Handle);
16 impl_handle_based!(Event);
17 impl Cookied for Event {}
18 
19 impl Event {
20     /// Create an event object, an object which is signalable but nothing else. Wraps the
21     /// [zx_event_create](https://fuchsia.googlesource.com/zircon/+/master/docs/syscalls/event_create.md)
22     /// syscall.
create() -> Result<Event, Status>23     pub fn create() -> Result<Event, Status> {
24         let mut out = 0;
25         let opts = 0;
26         let status = unsafe { sys::zx_event_create(opts, &mut out) };
27         ok(status)?;
28         unsafe {
29             Ok(Self::from(Handle::from_raw(out)))
30         }
31     }
32 }
33