xml_data/serializer/
fixed_element.rs

1use crate::{
2	serializer::{
3		Element,
4		Serializer,
5	},
6	Result,
7};
8use std::borrow::Cow;
9
10/// Serializable element with a fixed tag.
11pub trait FixedElement {
12	/// Fixed tag
13	const TAG: &'static str;
14
15	/// Same as `Element::serialize`.
16	fn serialize<S: Serializer>(&self, serializer: S) -> Result<()>;
17}
18
19impl<E: FixedElement> Element for E {
20	fn tag(&self) -> Cow<'_, str> {
21		Cow::Borrowed(Self::TAG)
22	}
23
24	fn serialize<S: Serializer>(&self, serializer: S) -> Result<()> {
25		<Self as FixedElement>::serialize(self, serializer)
26	}
27}