1use crate::{ok, sys, AsHandleRef, Handle, HandleBased, HandleRef, Port, Status};
8
9#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13#[repr(transparent)]
14pub struct Interrupt(Handle);
15impl_handle_based!(Interrupt);
16
17impl Interrupt {
18 pub fn bind_port(&self, port: &Port, key: u64) -> Result<(), Status> {
22 let options = sys::ZX_INTERRUPT_BIND;
23 let status =
24 unsafe { sys::zx_interrupt_bind(self.raw_handle(), port.raw_handle(), key, options) };
25 ok(status)
26 }
27
28 pub fn ack(&self) -> Result<(), Status> {
29 let status = unsafe { sys::zx_interrupt_ack(self.raw_handle()) };
30 ok(status)
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use crate::{Handle, Interrupt, Port, PortOptions, Status};
37
38 #[test]
39 fn bind() {
40 let interrupt: Interrupt = Handle::invalid().into();
41 let port = Port::create_with_opts(PortOptions::BIND_TO_INTERRUPT);
42 let key = 1;
43 let result = interrupt.bind_port(&port, key);
44 assert_eq!(result.err(), Some(Status::BAD_HANDLE));
45 }
46
47 #[test]
48 fn ack() {
49 let interrupt: Interrupt = Handle::invalid().into();
50 let result = interrupt.ack();
51 assert_eq!(result.err(), Some(Status::BAD_HANDLE));
52 }
53}