openthread::ot

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

Source§

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

Source§

type OtType = otBufferInfo

Source§

impl OtCastable for Info

Source§

type OtType = otMessageInfo

Source§

impl OtCastable for Settings

Source§

type OtType = otMessageSettings

Source§

impl OtCastable for ActiveScanResult

Source§

type OtType = otActiveScanResult

Source§

impl OtCastable for BackboneRouterMulticastListenerInfo

Source§

type OtType = otBackboneRouterMulticastListenerInfo

Source§

impl OtCastable for BorderRouterConfig

Source§

type OtType = otBorderRouterConfig

Source§

impl OtCastable for BorderRoutingCounters

Source§

type OtType = otBorderRoutingCounters

Source§

impl OtCastable for BorderRoutingPrefixTableEntry

Source§

type OtType = otBorderRoutingPrefixTableEntry

Source§

impl OtCastable for DnsTxtEntry<'_>

Source§

type OtType = otDnsTxtEntry

Source§

impl OtCastable for DnsTxtEntryIterator<'_>

Source§

type OtType = otDnsTxtEntryIterator

Source§

impl OtCastable for DnssdCounters

Source§

type OtType = otDnssdCounters

Source§

impl OtCastable for DnssdQuery

Source§

impl OtCastable for EnergyScanResult

Source§

type OtType = otEnergyScanResult

Source§

impl OtCastable for ExtAddress

Source§

type OtType = otExtAddress

Source§

impl OtCastable for ExtendedPanId

Source§

type OtType = otExtendedPanId

Source§

impl OtCastable for ExternalRouteConfig

Source§

type OtType = otExternalRouteConfig

Source§

impl OtCastable for Ip4Cidr

Source§

type OtType = otIp4Cidr

Source§

impl OtCastable for Ip6AddressInfo<'_>

Source§

type OtType = otIp6AddressInfo

Source§

impl OtCastable for Ip6NetworkPrefix

Source§

type OtType = otIp6NetworkPrefix

Source§

impl OtCastable for Ip6Prefix

Source§

type OtType = otIp6Prefix

Source§

impl OtCastable for IpCounters

Source§

type OtType = otIpCounters

Source§

impl OtCastable for LeaderData

Source§

type OtType = otLeaderData

Source§

impl OtCastable for LinkMetricsValues

Source§

type OtType = otLinkMetricsValues

Source§

impl OtCastable for MacCounters

Source§

type OtType = otMacCounters

Source§

impl OtCastable for Nat64AddressMapping

Source§

type OtType = otNat64AddressMapping

Source§

impl OtCastable for Nat64Counters

Source§

type OtType = otNat64Counters

Source§

impl OtCastable for Nat64ErrorCounters

Source§

type OtType = otNat64ErrorCounters

Source§

impl OtCastable for Nat64ProtocolCounters

Source§

type OtType = otNat64ProtocolCounters

Source§

impl OtCastable for NeighborInfo

Source§

type OtType = otNeighborInfo

Source§

impl OtCastable for NetifAddress

Source§

type OtType = otNetifAddress

Source§

impl OtCastable for NetworkKey

Source§

type OtType = otNetworkKey

Source§

impl OtCastable for NetworkName

Source§

type OtType = otNetworkName

Source§

impl OtCastable for OperationalDataset

Source§

type OtType = otOperationalDataset

Source§

impl OtCastable for OperationalDatasetTlvs

Source§

type OtType = otOperationalDatasetTlvs

Source§

impl OtCastable for PacketsAndBytes

Source§

type OtType = otPacketsAndBytes

Source§

impl OtCastable for PdProcessedRaInfo

Source§

type OtType = otPdProcessedRaInfo

Source§

impl OtCastable for PlatDnsUpstreamQuery

Source§

type OtType = otPlatDnsUpstreamQuery

Source§

impl OtCastable for PlatTrelPeerInfo<'_>

Source§

type OtType = otPlatTrelPeerInfo

Source§

impl OtCastable for Pskc

Source§

type OtType = otPskc

Source§

impl OtCastable for RadioCoexMetrics

Source§

type OtType = otRadioCoexMetrics

Source§

impl OtCastable for RouterInfo

Source§

type OtType = otRouterInfo

Source§

impl OtCastable for SecurityPolicy

Source§

type OtType = otSecurityPolicy

Source§

impl OtCastable for SockAddr

Source§

type OtType = otSockAddr

Source§

impl OtCastable for SrpServerHost

Source§

type OtType = otSrpServerHost

Source§

impl OtCastable for SrpServerLeaseInfo

Source§

type OtType = otSrpServerLeaseInfo

Source§

impl OtCastable for SrpServerResponseCounters

Source§

type OtType = otSrpServerResponseCounters

Source§

impl OtCastable for SrpServerService

Source§

type OtType = otSrpServerService

Source§

impl OtCastable for TrelCounters

Source§

type OtType = otPlatTrelCounters

Source§

impl OtCastable for UdpSocket<'_>

Source§

type OtType = otUdpSocket

Source§

impl OtCastable for UpstreamDnsCounters

Source§

type OtType = otUpstreamDnsCounters