openthread/ot/
uptime.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2022 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.

use crate::prelude_internal::*;

/// Uptime-related methods from the [OpenThread "Instance" Module][1].
///
/// [1]: https://openthread.io/reference/group/api-instance
pub trait Uptime {
    /// Functional equivalent of [`otsys::otInstanceGetUptime`](crate::otsys::otInstanceGetUptime).
    fn get_uptime(&self) -> zx::MonotonicDuration;
}

impl<T: Uptime + Boxable> Uptime for ot::Box<T> {
    fn get_uptime(&self) -> zx::MonotonicDuration {
        self.as_ref().get_uptime()
    }
}

impl Uptime for Instance {
    fn get_uptime(&self) -> zx::MonotonicDuration {
        unsafe {
            zx::MonotonicDuration::from_millis(
                otInstanceGetUptime(self.as_ot_ptr()).try_into().unwrap(),
            )
        }
    }
}