pub enum PrimitiveOrElement<P, E> {
Element(E),
Primitive(P),
}Expand description
Accepts either JSON primitive values or XML element structures with metadata.
JSON Format: Primitive values come through as scalars, metadata merged from _field by macro.
"birthDate": "1970-03-30"→Primitive("1970-03-30")(String directly)- Metadata in
_fieldis handled separately by the generated macro code
XML Format: All primitives are elements with inline metadata, no _field exists.
<birthDate value="1970-03-30"/>→Element(Element { value: Some(...), id: None, ... })<birthDate id="x" value="...">→Element(Element { value, id, ... })<birthDate id="x" value="..."><extension>...</extension></birthDate>→Elementwith full metadata
The custom Deserialize impl mirrors the old #[serde(untagged)] behavior without buffering:
- JSON scalars map to the
Primitivevariant (directly deserialized into the primitive type). - XML element structures (objects with
value,id,extension, …) map to theElementvariant. It avoids serde’s internalContentbuffering while preserving semantics crucial for primitives with metadata.
§Type Parameters
P: Primitive type (the final deserialized type, e.g.String,i32,bool)E: Element type (struct containing value and metadata fields)
Variants§
Trait Implementations§
Source§impl<P: Clone, E: Clone> Clone for PrimitiveOrElement<P, E>
impl<P: Clone, E: Clone> Clone for PrimitiveOrElement<P, E>
Source§fn clone(&self) -> PrimitiveOrElement<P, E>
fn clone(&self) -> PrimitiveOrElement<P, E>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'de, P, E> Deserialize<'de> for PrimitiveOrElement<P, E>where
P: Deserialize<'de>,
E: Deserialize<'de>,
Available on crate feature xml only.
impl<'de, P, E> Deserialize<'de> for PrimitiveOrElement<P, E>where
P: Deserialize<'de>,
E: Deserialize<'de>,
Available on crate feature
xml only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<P, E> StructuralPartialEq for PrimitiveOrElement<P, E>
Auto Trait Implementations§
impl<P, E> Freeze for PrimitiveOrElement<P, E>
impl<P, E> RefUnwindSafe for PrimitiveOrElement<P, E>where
E: RefUnwindSafe,
P: RefUnwindSafe,
impl<P, E> Send for PrimitiveOrElement<P, E>
impl<P, E> Sync for PrimitiveOrElement<P, E>
impl<P, E> Unpin for PrimitiveOrElement<P, E>
impl<P, E> UnsafeUnpin for PrimitiveOrElement<P, E>where
E: UnsafeUnpin,
P: UnsafeUnpin,
impl<P, E> UnwindSafe for PrimitiveOrElement<P, E>where
E: UnwindSafe,
P: 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