pub struct Tagged<T> {
pub tag: Option<u64>,
pub value: T,
}Expand description
A value with an optional CBOR tag.
When serialized the tag is written in front of the value, when
deserialized the tag (if there is one) is captured. If the value has
multiple tags, the outermost tag is captured and the inner tags are left
for the value (so Tagged<Tagged<T>> captures two tags).
use deser_cbor::Tagged;
// 1(1363896240): an epoch based date/time
let bytes = deser_cbor::to_vec(&Tagged::new(1, 1363896240u64)).unwrap();
assert_eq!(bytes, [0xc1, 0x1a, 0x51, 0x4b, 0x67, 0xb0]);
let value: Tagged<u64> = deser_cbor::from_slice(&bytes).unwrap();
assert_eq!(value.tag, Some(1));
assert_eq!(value.value, 1363896240);Other formats do not support tags. When serializing to such formats the
tag is dropped, when deserializing the tag is None.
Fields§
§tag: Option<u64>The tag of the value.
value: TThe value.
Implementations§
Trait Implementations§
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Tagged<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Tagged<T>
Source§fn deserialize_into<'out>(
out: &'out mut Option<Self>,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_into<'out>( out: &'out mut Option<Self>, state: &mut State, ) -> SinkHandle<'out, 'de>
Creates a sink that deserializes the value into the given slot. Read more
Source§fn expecting() -> Cow<'static, str>
fn expecting() -> Cow<'static, str>
Returns what the value expects, for error messages. Read more
Source§fn describe_type(d: &mut dyn Describe)
fn describe_type(d: &mut dyn Describe)
Describes the Rust shape of the type. Read more
Source§fn deserialize_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'_>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>
Deserializes an atom into the slot. Read more
Source§fn deserialize_borrowed_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'de>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>
Deserializes an atom that borrows from the data being deserialized
into the slot. Read more
Source§fn initial_value() -> Option<T>
fn initial_value() -> Option<T>
Provides the value of a missing struct field. Read more
Source§fn deserialize_update<'out>(
value: &'out mut T,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>
Creates a sink that updates an existing value. Read more
impl<T: Eq> Eq for Tagged<T>
Source§impl<T: Ord> Ord for Tagged<T>
impl<T: Ord> Ord for Tagged<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Tagged<T>
impl<T: PartialOrd> PartialOrd for Tagged<T>
Source§impl<T: Serialize> Serialize for Tagged<T>
impl<T: Serialize> Serialize for Tagged<T>
Source§fn serialize<'a>(this: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>
fn serialize<'a>(this: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>
Serializes the value.
Source§fn finish(this: &Self, state: &mut State) -> Result<(), Error>
fn finish(this: &Self, state: &mut State) -> Result<(), Error>
Invoked after the serialization finished. Read more
Source§fn is_optional(this: &Self) -> bool
fn is_optional(this: &Self) -> bool
Checks if the value represents an optional value. Read more
Source§fn container_shape(this: &Self) -> ContainerShape
fn container_shape(this: &Self) -> ContainerShape
Returns the shape of the value if it’s a map or sequence. Read more
impl<T: PartialEq> StructuralPartialEq for Tagged<T>
Auto Trait Implementations§
impl<T> Freeze for Tagged<T>where
T: Freeze,
impl<T> RefUnwindSafe for Tagged<T>where
T: RefUnwindSafe,
impl<T> Send for Tagged<T>where
T: Send,
impl<T> Sync for Tagged<T>where
T: Sync,
impl<T> Unpin for Tagged<T>where
T: Unpin,
impl<T> UnsafeUnpin for Tagged<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Tagged<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
Mutably borrows from an owned value. Read more