openthread/
lib.rs

1// Copyright 2022 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//! This crate contains a type-safe interface to the OpenThread API.
6//!
7//! This crate assumes that the OpenThread platform interface have been
8//! provided externally, perhaps by a separate crate.
9
10#![warn(missing_docs)]
11#![warn(missing_debug_implementations)]
12#![warn(rust_2018_idioms)]
13
14pub mod ot;
15pub use openthread_sys as otsys;
16
17mod bindings;
18
19#[cfg(target_os = "fuchsia")]
20mod otfuchsia;
21
22/// Shorthand for `ot::Box<T>`
23pub type OtBox<T> = ot::Box<T>;
24
25/// Shorthand for `ot::Box<ot::Instance>`.
26pub type OtInstanceBox = ot::Box<ot::Instance>;
27
28/// Shorthand for `ot::Box<ot::Message<'a>>`.
29pub type OtMessageBox<'a> = ot::Box<ot::Message<'a>>;
30
31/// Prelude namespace for improving the ergonomics of using this crate.
32#[macro_use]
33pub mod prelude {
34    #![allow(unused_imports)]
35
36    pub use crate::bindings::*;
37    pub use crate::{ot, otsys, OtBox, OtInstanceBox, OtMessageBox};
38    pub use ot::{
39        BackboneRouter as _, BorderRouter as _, Boxable as _, Dnssd as _, DnssdExt as _,
40        IntoOtError as _, Ip6 as _, Link as _, MessageBuffer as _, OtCastable as _, Reset as _,
41        SrpServer as _, State as _, Tasklets as _, Thread as _, Udp as _, Uptime as _,
42    };
43
44    pub use ot::TaskletsStreamExt as _;
45    pub use std::convert::{TryFrom as _, TryInto as _};
46}
47
48// Internal prelude namespace for internal crate use only.
49#[doc(hidden)]
50#[macro_use]
51pub(crate) mod prelude_internal {
52    #![allow(unused_imports)]
53
54    pub use crate::impl_ot_castable;
55    pub use crate::otsys::*;
56    pub use crate::prelude::*;
57    pub use core::convert::{TryFrom, TryInto};
58    pub use futures::prelude::*;
59    pub use log::{debug, error, info, trace, warn};
60    pub use num::FromPrimitive as _;
61    pub(crate) use ot::ascii_dump;
62    pub use ot::types::*;
63    pub use ot::{
64        BackboneRouter, BorderRouter, Boxable, Error, Instance, InstanceInterface, Ip6, Link,
65        Message, MessageBuffer, Platform, Result, SrpServer, Tasklets, Thread,
66    };
67    pub use static_assertions as sa;
68    pub use std::ffi::{CStr, CString};
69    pub use std::marker::PhantomData;
70    pub use std::os::raw::c_char;
71    pub use std::ptr::null;
72}