Trait openthread::ot::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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl OtCastable for Ipv6Addr

§

type OtType = otIp6Address

source§

fn as_ot_ptr(&self) -> *const otIp6Address

source§

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

source§

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

source§

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

Implementors§

source§

impl OtCastable for BufferInfo

§

type OtType = otBufferInfo

source§

impl OtCastable for Info

§

type OtType = otMessageInfo

source§

impl OtCastable for Settings

§

type OtType = otMessageSettings

source§

impl OtCastable for ActiveScanResult

§

type OtType = otActiveScanResult

source§

impl OtCastable for BackboneRouterMulticastListenerInfo

§

type OtType = otBackboneRouterMulticastListenerInfo

source§

impl OtCastable for BorderRouterConfig

§

type OtType = otBorderRouterConfig

source§

impl OtCastable for BorderRoutingCounters

§

type OtType = otBorderRoutingCounters

source§

impl OtCastable for BorderRoutingPrefixTableEntry

§

type OtType = otBorderRoutingPrefixTableEntry

source§

impl OtCastable for DnsTxtEntry<'_>

§

type OtType = otDnsTxtEntry

source§

impl OtCastable for DnsTxtEntryIterator<'_>

§

type OtType = otDnsTxtEntryIterator

source§

impl OtCastable for DnssdCounters

§

type OtType = otDnssdCounters

source§

impl OtCastable for DnssdQuery

source§

impl OtCastable for EnergyScanResult

§

type OtType = otEnergyScanResult

source§

impl OtCastable for ExtAddress

§

type OtType = otExtAddress

source§

impl OtCastable for ExtendedPanId

§

type OtType = otExtendedPanId

source§

impl OtCastable for ExternalRouteConfig

§

type OtType = otExternalRouteConfig

source§

impl OtCastable for Ip4Cidr

§

type OtType = otIp4Cidr

source§

impl OtCastable for Ip6AddressInfo<'_>

§

type OtType = otIp6AddressInfo

source§

impl OtCastable for Ip6NetworkPrefix

§

type OtType = otIp6NetworkPrefix

source§

impl OtCastable for Ip6Prefix

§

type OtType = otIp6Prefix

source§

impl OtCastable for IpCounters

§

type OtType = otIpCounters

source§

impl OtCastable for LeaderData

§

type OtType = otLeaderData

source§

impl OtCastable for MacCounters

§

type OtType = otMacCounters

source§

impl OtCastable for Nat64AddressMapping

§

type OtType = otNat64AddressMapping

source§

impl OtCastable for Nat64Counters

§

type OtType = otNat64Counters

source§

impl OtCastable for Nat64ErrorCounters

§

type OtType = otNat64ErrorCounters

source§

impl OtCastable for Nat64ProtocolCounters

§

type OtType = otNat64ProtocolCounters

source§

impl OtCastable for NeighborInfo

§

type OtType = otNeighborInfo

source§

impl OtCastable for NetifAddress

§

type OtType = otNetifAddress

source§

impl OtCastable for NetworkKey

§

type OtType = otNetworkKey

source§

impl OtCastable for NetworkName

§

type OtType = otNetworkName

source§

impl OtCastable for OperationalDataset

§

type OtType = otOperationalDataset

source§

impl OtCastable for OperationalDatasetTlvs

§

type OtType = otOperationalDatasetTlvs

source§

impl OtCastable for PacketsAndBytes

§

type OtType = otPacketsAndBytes

source§

impl OtCastable for PdProcessedRaInfo

§

type OtType = otPdProcessedRaInfo

source§

impl OtCastable for PlatDnsUpstreamQuery

§

type OtType = otPlatDnsUpstreamQuery

source§

impl OtCastable for PlatTrelPeerInfo<'_>

§

type OtType = otPlatTrelPeerInfo

source§

impl OtCastable for Pskc

§

type OtType = otPskc

source§

impl OtCastable for RadioCoexMetrics

§

type OtType = otRadioCoexMetrics

source§

impl OtCastable for RouterInfo

§

type OtType = otRouterInfo

source§

impl OtCastable for SecurityPolicy

§

type OtType = otSecurityPolicy

source§

impl OtCastable for SockAddr

§

type OtType = otSockAddr

source§

impl OtCastable for SrpServerHost

§

type OtType = otSrpServerHost

source§

impl OtCastable for SrpServerLeaseInfo

§

type OtType = otSrpServerLeaseInfo

source§

impl OtCastable for SrpServerResponseCounters

§

type OtType = otSrpServerResponseCounters

source§

impl OtCastable for SrpServerService

§

type OtType = otSrpServerService

source§

impl OtCastable for TrelCounters

§

type OtType = otPlatTrelCounters

source§

impl OtCastable for UdpSocket<'_>

§

type OtType = otUdpSocket

source§

impl OtCastable for UpstreamDnsCounters

§

type OtType = otUpstreamDnsCounters