use mtp::codec::{CommunicationValue, DataValue}; use mtp::type_map::DataTypeId; /* * Keep legacy control-plane handlers source-compatible while they migrate to * MTP's explicit optional routing fields. Relay handlers must use sender() and * receiver() directly so an absent outer sender cannot become an identity. */ pub trait CommunicationValueCompat { fn get_id(&self) -> u32; fn get_sender(&self) -> u64; fn get_receiver(&self) -> u64; } impl CommunicationValueCompat for CommunicationValue { fn get_id(&self) -> u32 { self.id().unwrap_or_default() } fn get_sender(&self) -> u64 { self.sender().unwrap_or_default() } fn get_receiver(&self) -> u64 { self.receiver().unwrap_or_default() } } pub trait OptionalDataValueExt<'a> { fn as_bool(self) -> Option; fn as_str(self) -> Option<&'a str>; fn as_string(self) -> Option; fn as_number(self) -> Option; fn as_signed_number(self) -> Option; fn as_array(self) -> Option>; fn as_container(self) -> Option>; } impl<'a> OptionalDataValueExt<'a> for Option<&'a DataValue> { fn as_bool(self) -> Option { self.and_then(DataValue::as_bool) } fn as_str(self) -> Option<&'a str> { self.and_then(DataValue::as_str) } fn as_string(self) -> Option { self.and_then(DataValue::as_string) } fn as_number(self) -> Option { self.and_then(DataValue::as_number) } fn as_signed_number(self) -> Option { self.and_then(DataValue::as_signed_number) } fn as_array(self) -> Option> { self.and_then(DataValue::as_array) } fn as_container(self) -> Option> { self.and_then(DataValue::as_container) } }