OtCastable

Trait OtCastable 

Source
pub unsafe trait OtCastable: Sized {
    type OtType: Sized;

    // Required methods
    fn as_ot_ptr(&self) -> *const Self::OtType;
    fn as_ot_mut_ptr(&mut self) -> *mut Self::OtType;
    unsafe fn ref_from_ot_ptr<'a>(ptr: *const Self::OtType) -> Option<&'a Self>;
    unsafe fn mut_from_ot_mut_ptr<'a>(
        ptr: *mut Self::OtType,
    ) -> Option<&'a mut Self>;

    // Provided methods
    fn as_ot_ref(&self) -> &Self::OtType { ... }
    fn as_ot_mut(&mut self) -> &mut Self::OtType { ... }
    fn ref_from_ot_ref(x: &Self::OtType) -> &Self { ... }
}
Expand description

Trait used to indicate that the implementing type can be efficiently converted into a reference to the original OpenThread type identified by Self::OtType.

Types which implement this trait may be opaque, but, unlike [Boxable], these types are not necessarily opaque and not necessarily ownable. If a type is not opaque then it will also implement the related trait Transparent, allowing it to be used by value.

§Safety

This trait is unsafe because it is making an assertion about the data’s representation that must be verified by code review.

In order to safely implement this trait you must verify that the implementing type is guaranteed to always be fundamentally identical in its in-memory representation to <Self as OtCastable>::OtType.

For example, this would be the case if Self is #[repr(transparent)] and has only a single member of <Self as OtCastable>::OtType.

Required Associated Types§

Source

type OtType: Sized

Original OpenThread Type.

Required Methods§

Source

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

Returns a pointer to the underlying Self::OtType instance.

Source

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

Returns a mutable pointer to the underlying Self::OtType instance.

Source

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

Creates a reference from a pointer to an Self::OtType.

§Safety

This method is unsafe because unchecked conversion of pointers to references is generally unsafe. The following assumptions need to be verified to avoid undefined behavior:

  1. ptr MUST point to a valid instance of Self::OtType that will remain valid over the given lifetime.
Source

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

Creates a mut reference from a mut pointer to an Self::OtType.

§Safety

This method is unsafe because unchecked conversion of pointers to references is generally unsafe. The following assumptions need to be verified to avoid undefined behavior:

  1. ptr MUST point to a valid instance of Self::OtType that will remain valid over the given lifetime.

Provided Methods§

Source

fn as_ot_ref(&self) -> &Self::OtType

Returns a reference to the original OpenThread type Self::OtType.

Source

fn as_ot_mut(&mut self) -> &mut Self::OtType

Returns a mutable reference to the original OpenThread type Self::OtType.

Source

fn ref_from_ot_ref(x: &Self::OtType) -> &Self

Casts a reference to the original OpenThread type to a reference to Self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl OtCastable for Ipv6Addr

Implementors§

Source§

impl OtCastable for BufferInfo

Source§

impl OtCastable for Info

Source§

impl OtCastable for Settings

Source§

impl OtCastable for ActiveScanResult

Source§

impl OtCastable for BackboneRouterMulticastListenerInfo

Source§

impl OtCastable for BorderRouterConfig

Source§

impl OtCastable for BorderRoutingCounters

Source§

impl OtCastable for BorderRoutingPrefixTableEntry

Source§

impl OtCastable for DnsTxtEntry<'_>

Source§

impl OtCastable for DnsTxtEntryIterator<'_>

Source§

impl OtCastable for DnssdCounters

Source§

impl OtCastable for DnssdQuery

Source§

impl OtCastable for EnergyScanResult

Source§

impl OtCastable for ExtAddress

Source§

impl OtCastable for ExtendedPanId

Source§

impl OtCastable for ExternalRouteConfig

Source§

impl OtCastable for Ip4Cidr

Source§

impl OtCastable for Ip6AddressInfo<'_>

Source§

impl OtCastable for Ip6NetworkPrefix

Source§

impl OtCastable for Ip6Prefix

Source§

impl OtCastable for IpCounters

Source§

impl OtCastable for LeaderData

Source§

impl OtCastable for LinkMetricsValues

Source§

impl OtCastable for MacCounters

Source§

impl OtCastable for Nat64AddressMapping

Source§

impl OtCastable for Nat64Counters

Source§

impl OtCastable for Nat64ErrorCounters

Source§

impl OtCastable for Nat64ProtocolCounters

Source§

impl OtCastable for NeighborInfo

Source§

impl OtCastable for NetifAddress

Source§

impl OtCastable for NetworkKey

Source§

impl OtCastable for NetworkName

Source§

impl OtCastable for OperationalDataset

Source§

impl OtCastable for OperationalDatasetTlvs

Source§

impl OtCastable for PacketsAndBytes

Source§

impl OtCastable for PdProcessedRaInfo

Source§

impl OtCastable for PlatDnsUpstreamQuery

Source§

impl OtCastable for PlatTrelPeerInfo<'_>

Source§

impl OtCastable for Pskc

Source§

impl OtCastable for RadioCoexMetrics

Source§

impl OtCastable for RouterInfo

Source§

impl OtCastable for SecurityPolicy

Source§

impl OtCastable for SockAddr

Source§

impl OtCastable for SrpServerHost

Source§

impl OtCastable for SrpServerLeaseInfo

Source§

impl OtCastable for SrpServerResponseCounters

Source§

impl OtCastable for SrpServerService

Source§

impl OtCastable for TrelCounters

Source§

impl OtCastable for UdpSocket<'_>

Source§

impl OtCastable for UpstreamDnsCounters