openthread/ot/types/
cache_entry_info.rs1use crate::prelude_internal::*;
6use std::fmt::{Debug, Formatter};
7
8#[derive(Default, Clone, Copy)]
10#[repr(transparent)]
11pub struct CacheEntryInfo(pub otCacheEntryInfo);
12
13impl_ot_castable!(CacheEntryInfo, otCacheEntryInfo);
14
15#[derive(Debug, Copy, Clone, Eq, Ord, PartialOrd, PartialEq, num_derive::FromPrimitive)]
19#[allow(missing_docs)]
20pub enum CacheEntryState {
21 Cached = OT_CACHE_ENTRY_STATE_CACHED as isize,
22 Snooped = OT_CACHE_ENTRY_STATE_SNOOPED as isize,
23 Query = OT_CACHE_ENTRY_STATE_QUERY as isize,
24 Retry = OT_CACHE_ENTRY_STATE_RETRY_QUERY as isize,
25 Unknown,
26}
27
28impl From<otCacheEntryState> for CacheEntryState {
29 fn from(x: otCacheEntryState) -> Self {
30 use num::FromPrimitive;
31 Self::from_u32(x).unwrap_or_else(|| {
32 warn!("Unknown otCacheEntryState value: {x}. Falling back to default state.");
33 CacheEntryState::Unknown
34 })
35 }
36}
37
38impl Debug for CacheEntryInfo {
39 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40 f.debug_struct("CacheEntryInfo")
41 .field("target", &self.target())
42 .field("rloc16", &self.rloc16())
43 .field("state", &self.state())
44 .field("can_evict", &self.can_evict())
45 .field("ramp_down", &self.ramp_down())
46 .field("valid_last_trans", &self.valid_last_trans())
47 .field("last_trans_time", &self.last_trans_time())
48 .field("mesh_local_eid", &self.mesh_local_eid())
49 .field("timeout", &self.timeout())
50 .field("retry_delay", &self.retry_delay())
51 .finish()
52 }
53}
54
55impl CacheEntryInfo {
56 pub fn target(&self) -> &Ip6Address {
58 Ip6Address::ref_from_ot_ref(&self.0.mTarget)
59 }
60
61 pub fn rloc16(&self) -> ShortAddress {
63 self.0.mRloc16
64 }
65
66 pub fn state(&self) -> CacheEntryState {
68 CacheEntryState::from(self.0.mState)
69 }
70
71 pub fn can_evict(&self) -> bool {
73 self.0.mCanEvict()
74 }
75
76 pub fn ramp_down(&self) -> bool {
78 self.0.mRampDown()
79 }
80
81 pub fn valid_last_trans(&self) -> bool {
83 self.0.mValidLastTrans()
84 }
85
86 pub fn last_trans_time(&self) -> u32 {
88 self.0.mLastTransTime
89 }
90
91 pub fn mesh_local_eid(&self) -> &Ip6Address {
93 Ip6Address::ref_from_ot_ref(&self.0.mMeshLocalEid)
94 }
95
96 pub fn timeout(&self) -> u16 {
98 self.0.mTimeout
99 }
100
101 pub fn retry_delay(&self) -> u16 {
103 self.0.mRetryDelay
104 }
105}