Trait openthread::ot::Boxable

source ·
pub unsafe trait Boxable: Sized {
    type OtType: Sized;

    // Required method
    unsafe fn finalize(&mut self);

    // Provided methods
    unsafe fn ref_from_ot_ptr<'a>(ptr: *mut Self::OtType) -> Option<&'a Self> { ... }
    unsafe fn ref_from_ot_const_ptr<'a>(
        ptr: *const Self::OtType
    ) -> Option<&'a Self> { ... }
    unsafe fn mut_from_ot_ptr<'a>(
        ptr: *mut Self::OtType
    ) -> Option<&'a mut Self> { ... }
    fn as_ot_ptr(&self) -> *mut Self::OtType { ... }
}
Expand description

Trait for OpenThread Rust types for which an owned opaque instance is kept in a [ot::Box<>].

§Safety

The safety of implementing this trait is dependent on the following assumptions:

  1. The type Self is never instantiated or passed by value. It must only ever used by reference (&Self or &mut Self).
  2. No member of Self is ever accessed directly or exposed publicly.

Because of the above restrictions, Self is usually a zero-sized type.

Required Associated Types§

source

type OtType: Sized

The underlying implementation-opaque OpenThread type used by the standard C-API.

Required Methods§

source

unsafe fn finalize(&mut self)

Finalizes or frees the underlying OpenThread object.

This method should only be called by the Drop::drop method on ot::Box. It should not be called directly. This is usually the only method that needs to be implemented from this trait: the default implementations of the other methods is sufficient.

§Safety

This method is considered unsafe to call directly because it invalidates the underlying OpenThread object. This method should only ever be called from a single place: Drop::drop() on ot::Box.

Provided Methods§

source

unsafe fn ref_from_ot_ptr<'a>(ptr: *mut Self::OtType) -> Option<&'a Self>

Creates a reference to a safe wrapper object from an OpenThread pointer.

§Safety

This method is unsafe because it allows you to cast an arbitrary pointer to a reference. When calling, care must be taken to ensure the following is true:

  1. The given pointer points to a valid instance of Self::OtType for the given lifetime.
source

unsafe fn ref_from_ot_const_ptr<'a>( ptr: *const Self::OtType ) -> Option<&'a Self>

Creates a reference to a safe wrapper object from an OpenThread const pointer.

§Safety

This method is unsafe because it allows you to cast an arbitrary pointer to a reference. When calling, care must be taken to ensure the following is true:

  1. The given pointer points to a valid instance of Self::OtType for the given lifetime.
source

unsafe fn mut_from_ot_ptr<'a>(ptr: *mut Self::OtType) -> Option<&'a mut Self>

Creates a mutable reference to a safe wrapper object from an OpenThread pointer.

§Safety

This method is unsafe because it allows you to cast an arbitrary pointer to a reference. When calling, care must be taken to ensure the following is true:

  1. The given pointer points to a valid instance of Self::OtType.
  2. The given pointer is not NULL.
source

fn as_ot_ptr(&self) -> *mut Self::OtType

Returns the underlying OpenThread pointer for this object. The default implementation simply casts the reference to a pointer.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Boxable for Instance

§

type OtType = otInstance

source§

impl<'a> Boxable for Message<'a>

§

type OtType = otMessage