// Copyright 2016 The Fuchsia Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. //! Type-safe bindings for Zircon timer objects. use {AsHandleRef, ClockId, HandleBased, Handle, HandleRef, Status}; use {sys, ok}; use std::ops; use std::time as stdtime; #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct Duration(sys::zx_duration_t); #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct Time(sys::zx_time_t); impl From for Duration { fn from(dur: stdtime::Duration) -> Self { Duration::from_seconds(dur.as_secs()) + Duration::from_nanos(dur.subsec_nanos() as u64) } } impl From for stdtime::Duration { fn from(dur: Duration) -> Self { let secs = dur.seconds(); let nanos = (dur.nanos() - (secs * 1_000_000_000)) as u32; stdtime::Duration::new(secs, nanos) } } impl ops::Add for Time { type Output = Time; fn add(self, dur: Duration) -> Time { Time::from_nanos(dur.nanos() + self.nanos()) } } impl ops::Add