xsd_parser/quick_xml/
attributes.rs1use quick_xml::events::{
2 attributes::{AttrError, Attribute},
3 BytesStart,
4};
5
6use super::{Error, SerializeBytes};
7
8pub fn write_attrib<T>(bytes: &mut BytesStart<'_>, name: &str, attrib: &T) -> Result<(), Error>
13where
14 T: SerializeBytes,
15{
16 if let Some(attrib) = SerializeBytes::serialize_bytes(attrib)? {
17 bytes.push_attribute((name, attrib));
18 }
19
20 Ok(())
21}
22
23pub fn write_attrib_opt<T>(
28 bytes: &mut BytesStart<'_>,
29 name: &str,
30 attrib: &Option<T>,
31) -> Result<(), Error>
32where
33 T: SerializeBytes,
34{
35 let Some(attrib) = attrib else {
36 return Ok(());
37 };
38
39 write_attrib(bytes, name, attrib)
40}
41
42pub fn filter_xmlns_attributes<'a>(
45 bytes_start: &'a BytesStart<'_>,
46) -> impl Iterator<Item = Result<Attribute<'a>, AttrError>> {
47 bytes_start.attributes().filter(|attrib| {
48 let Ok(attrib) = attrib else {
49 return true;
50 };
51
52 attrib.key.0 != b"xmlns" && !attrib.key.0.starts_with(b"xmlns:")
53 })
54}