openthread

Module ot

Source
Expand description

§OpenThread API Module

This module contains (mostly) type-safe versions of the OpenThread API, excluding the platform API.

§Type Safety

Full type safety for an API which wasn’t created for type safety is hard. There are some operations which feel like they should be fully safe but are ultimately marked as unsafe because it might be possible to abuse in some way that causes undefined behavior.

§Types

Each enum, struct, or object in the OpenThread C API is associated with a safe Rust equivalent. For example:

§Ownership

Some OpenThread API objects, like otsys::otInstance and otsys::otMessage have hidden implementations and explicit ownership transfer. That means we must have a notation which is capable of both “owned” instances and “borrowed” references.

The rust equivalent of passing around a pointer to one of thse objects would be to pass around a reference: otInstance* becomes a &ot::Instance. Owned instances are “boxed” into a ot::Box, so an owned otInstance* would become a ot::Box<ot::Instance>, or a OtInstanceBox for short. When the box goes out of scope, the appropriate OpenThread C finalization API is called.

§Singleton/Multiple OpenThread Instances

OpenThread can be compiled to either only support a singleton instance or to support multiple independent OpenThread instances.

Currently, this crate only supports a singleton OpenThread instance. Attempting to create more than one OpenThread instance at a time will result in a runtime panic.

§Traits

The OpenThread API is broken down into “modules” of functionality containing types and related methods. Similarly, this Rust interface breaks down functionality into traits. This allows parts of the OpenThread API to be substituted with mocked versions for unit testing.

§Callbacks

In most cases, you register a callback by passing a closure to the appropriate callback registration API.

§Platform Implementations

This crate doesn’t directly provide the platform implementations for OpenThread—that needs to come from either a separate library or the program which is using this crate.

Re-exports§

Modules§

  • Module for all things related to OpenThread messages.

Structs§

Enums§

Constants§

Traits§

Functions§

Type Aliases§