Struct relay_protocol::Annotated
source · pub struct Annotated<T>(pub Option<T>, pub Meta);
Expand description
Wrapper for data fields with optional meta data.
Tuple Fields§
§0: Option<T>
§1: Meta
Implementations§
source§impl<T> Annotated<T>
impl<T> Annotated<T>
sourcepub fn from_error<E>(err: E, value: Option<Value>) -> Self
pub fn from_error<E>(err: E, value: Option<Value>) -> Self
Creates an empty annotated value with error attached.
sourcepub fn value(&self) -> Option<&T>
pub fn value(&self) -> Option<&T>
Returns a reference to the value.
Returns None
if this value is not initialized, missing, or invalid.
sourcepub fn value_mut(&mut self) -> &mut Option<T>
pub fn value_mut(&mut self) -> &mut Option<T>
Returns a mutable reference to the value.
Returns None
if this value is not initialized, missing, or invalid.
sourcepub fn meta_mut(&mut self) -> &mut Meta
pub fn meta_mut(&mut self) -> &mut Meta
Returns a mutable reference to the meta data attached to this value.
sourcepub fn into_value(self) -> Option<T>
pub fn into_value(self) -> Option<T>
Returns the stored value and drops all meta data.
sourcepub fn and_then<F, U, R>(self, f: F) -> Annotated<U>
pub fn and_then<F, U, R>(self, f: F) -> Annotated<U>
Calls f
with the stored value if available and merges meta data into the result.
sourcepub fn map_value<U, F>(self, f: F) -> Annotated<U>where
F: FnOnce(T) -> U,
pub fn map_value<U, F>(self, f: F) -> Annotated<U>where
F: FnOnce(T) -> U,
Maps an Annotated<T>
to an Annotated<U>
and keeps the original meta data.
sourcepub fn get_or_insert_with<F>(&mut self, f: F) -> &mut Twhere
F: FnOnce() -> T,
pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut Twhere
F: FnOnce() -> T,
Inserts a value computed from f
into the value if it is None
, then returns a mutable
reference to the contained value.
source§impl<T> Annotated<T>where
T: Empty,
impl<T> Annotated<T>where
T: Empty,
sourcepub fn skip_serialization(&self, behavior: SkipSerialization) -> bool
pub fn skip_serialization(&self, behavior: SkipSerialization) -> bool
Returns whether this value should be skipped during serialization.
An Annotated<T>
is always serialized if it has meta data. Otherwise, serialization
depends on the behavior. For SkipSerialization::Empty
, the Empty
trait is used to
determine emptiness of the contained value and defaults to false
for no value.
source§impl<T> Annotated<T>where
T: FromValue,
impl<T> Annotated<T>where
T: FromValue,
sourcepub fn deserialize_with_meta<'de, D: Deserializer<'de>>(
deserializer: D,
) -> Result<Self, D::Error>
pub fn deserialize_with_meta<'de, D: Deserializer<'de>>( deserializer: D, ) -> Result<Self, D::Error>
Deserializes an annotated from a deserializer
sourcepub fn from_json_bytes(b: &[u8]) -> Result<Self, Error>
pub fn from_json_bytes(b: &[u8]) -> Result<Self, Error>
Deserializes an annotated from JSON bytes.
source§impl<T> Annotated<T>where
T: IntoValue,
impl<T> Annotated<T>where
T: IntoValue,
sourcepub fn serialize_with_meta<S: Serializer>(
&self,
serializer: S,
) -> Result<S::Ok, S::Error>
pub fn serialize_with_meta<S: Serializer>( &self, serializer: S, ) -> Result<S::Ok, S::Error>
Serializes an annotated value into a serializer.
sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Serializes an annotated value into a JSON string.
sourcepub fn to_json_pretty(&self) -> Result<String, Error>
pub fn to_json_pretty(&self) -> Result<String, Error>
Serializes an annotated value into a pretty JSON string.
sourcepub fn payload_to_json(&self) -> Result<String, Error>
pub fn payload_to_json(&self) -> Result<String, Error>
Serializes an annotated value into a JSON string.
sourcepub fn payload_to_json_pretty(&self) -> Result<String, Error>
pub fn payload_to_json_pretty(&self) -> Result<String, Error>
Serializes an annotated value into a pretty JSON string.
Trait Implementations§
source§impl<T> Empty for Annotated<T>where
T: Empty,
impl<T> Empty for Annotated<T>where
T: Empty,
Checks whether annotated data contains either a value or meta data.
source§fn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns if this object contains data to be serialized.
Caution: This has different behavior than annotated.value().is_empty()
! Annotated is
not empty if there is meta data that needs to be serialized. This is in line with the
derived implementation of Empty
on structs, which calls Annotated::is_empty
on every
child.
To check if a value is missing or empty, use Option::is_empty
on the value instead.
source§fn is_deep_empty(&self) -> bool
fn is_deep_empty(&self) -> bool
Returns if this object contains nested data to be serialized.
impl<T> StructuralPartialEq for Annotated<T>
Auto Trait Implementations§
impl<T> Freeze for Annotated<T>where
T: Freeze,
impl<T> RefUnwindSafe for Annotated<T>where
T: RefUnwindSafe,
impl<T> Send for Annotated<T>where
T: Send,
impl<T> Sync for Annotated<T>where
T: Sync,
impl<T> Unpin for Annotated<T>where
T: Unpin,
impl<T> UnwindSafe for Annotated<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)