openthread/ot/reset.rs
1// Copyright 2021 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 crate::prelude_internal::*;
6
7/// Reset-related methods from the [OpenThread "Instance" Module][1].
8///
9/// [1]: https://openthread.io/reference/group/api-instance
10pub trait Reset {
11 /// Functional equivalent of [`otsys::otInstanceReset`](crate::otsys::otInstanceReset).
12 fn reset(&self);
13
14 /// Functional equivalent of
15 /// [`otsys::otInstanceFactoryReset`](crate::otsys::otInstanceFactoryReset).
16 fn factory_reset(&self);
17
18 /// Functional equivalent of
19 /// [`otsys::otInstanceErasePersistentInfo`](crate::otsys::otInstanceErasePersistentInfo).
20 fn erase_persistent_info(&self) -> Result;
21}
22
23impl<T: Reset + Boxable> Reset for ot::Box<T> {
24 fn reset(&self) {
25 self.as_ref().reset()
26 }
27 fn factory_reset(&self) {
28 self.as_ref().factory_reset()
29 }
30 fn erase_persistent_info(&self) -> Result {
31 self.as_ref().erase_persistent_info()
32 }
33}
34
35impl Reset for Instance {
36 fn reset(&self) {
37 unsafe { otInstanceReset(self.as_ot_ptr()) }
38 }
39
40 fn factory_reset(&self) {
41 unsafe { otInstanceFactoryReset(self.as_ot_ptr()) }
42 }
43
44 fn erase_persistent_info(&self) -> Result {
45 Error::from(unsafe { otInstanceErasePersistentInfo(self.as_ot_ptr()) }).into()
46 }
47}