xsd-parser 1.5.2

Rust code generator for XML schema files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
pub const NS_XS: xsd_parser_types::misc::Namespace =
    xsd_parser_types::misc::Namespace::new_const(b"http://www.w3.org/2001/XMLSchema");
pub const NS_XML: xsd_parser_types::misc::Namespace =
    xsd_parser_types::misc::Namespace::new_const(b"http://www.w3.org/XML/1998/namespace");
pub const NS_XSI: xsd_parser_types::misc::Namespace =
    xsd_parser_types::misc::Namespace::new_const(b"http://www.w3.org/2001/XMLSchema-instance");
pub const PREFIX_XS: xsd_parser_types::misc::NamespacePrefix =
    xsd_parser_types::misc::NamespacePrefix::new_const(b"xs");
pub const PREFIX_XML: xsd_parser_types::misc::NamespacePrefix =
    xsd_parser_types::misc::NamespacePrefix::new_const(b"xml");
pub const PREFIX_XSI: xsd_parser_types::misc::NamespacePrefix =
    xsd_parser_types::misc::NamespacePrefix::new_const(b"xsi");
pub type AsMut = TestType;
pub type AsRef = TestType;
pub type Box = TestType;
pub type Clone = TestType;
pub type Copy = TestType;
pub type Debug = TestType;
pub type Default = TestType;
pub type Drop = TestType;
pub type Eq = TestType;
pub type Fn = TestType;
pub type FnMut = TestType;
pub type FnOnce = TestType;
pub type From = TestType;
pub type FromIterator = TestType;
pub type Into = TestType;
pub type IntoIterator = TestType;
pub type Iterator = TestType;
pub type Option = TestType;
pub type Ord = TestType;
pub type PartialEq = TestType;
pub type PartialOrd = TestType;
pub type Result = TestType;
pub type Send = TestType;
pub type Sized = TestType;
pub type String = TestType;
pub type Sync = TestType;
#[derive(Debug)]
pub struct TestType(pub ::std::string::String);
impl TestType {
    pub fn new(
        inner: ::std::string::String,
    ) -> ::core::result::Result<Self, ::xsd_parser_types::quick_xml::ValidateError> {
        Self::validate_value(&inner)?;
        Ok(Self(inner))
    }
    #[must_use]
    pub fn into_inner(self) -> ::std::string::String {
        self.0
    }
    pub fn validate_value(
        value: &::std::string::String,
    ) -> ::core::result::Result<(), ::xsd_parser_types::quick_xml::ValidateError> {
        if !value.is_empty() {
            return Err(::xsd_parser_types::quick_xml::ValidateError::MaxLength(
                0usize,
            ));
        }
        Ok(())
    }
}
impl ::core::convert::From<TestType> for ::std::string::String {
    fn from(value: TestType) -> ::std::string::String {
        value.0
    }
}
impl ::core::convert::TryFrom<::std::string::String> for TestType {
    type Error = ::xsd_parser_types::quick_xml::ValidateError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::core::result::Result<Self, ::xsd_parser_types::quick_xml::ValidateError> {
        Self::new(value)
    }
}
impl ::core::ops::Deref for TestType {
    type Target = ::std::string::String;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl ::xsd_parser_types::quick_xml::SerializeBytes for TestType {
    fn serialize_bytes(
        &self,
        helper: &mut ::xsd_parser_types::quick_xml::SerializeHelper,
    ) -> ::core::result::Result<
        ::core::option::Option<::std::borrow::Cow<'_, ::core::primitive::str>>,
        ::xsd_parser_types::quick_xml::Error,
    > {
        self.0.serialize_bytes(helper)
    }
}
impl xsd_parser_types::quick_xml::WithSerializeToBytes for TestType {}
impl ::xsd_parser_types::quick_xml::DeserializeBytes for TestType {
    fn deserialize_bytes(
        helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
        bytes: &[::core::primitive::u8],
    ) -> ::core::result::Result<Self, ::xsd_parser_types::quick_xml::Error> {
        let inner = ::std::string::String::deserialize_bytes(helper, bytes)?;
        Ok(Self::new(inner).map_err(|error| (bytes, error))?)
    }
}
impl xsd_parser_types::quick_xml::WithDeserializerFromBytes for TestType {}
pub type ToString = TestType;
pub type TryFrom = TestType;
pub type TryInto = TestType;
pub type Unpin = TestType;
pub type Vec = TestType;
#[derive(Debug, Default)]
pub struct EntitiesType(pub ::std::vec::Vec<::std::string::String>);
impl ::xsd_parser_types::quick_xml::SerializeBytes for EntitiesType {
    fn serialize_bytes(
        &self,
        helper: &mut ::xsd_parser_types::quick_xml::SerializeHelper,
    ) -> ::core::result::Result<
        ::core::option::Option<::std::borrow::Cow<'_, ::core::primitive::str>>,
        ::xsd_parser_types::quick_xml::Error,
    > {
        if self.0.is_empty() {
            return Ok(None);
        }
        let mut data = ::std::string::String::new();
        for item in &self.0 {
            if let Some(bytes) = item.serialize_bytes(helper)? {
                if !data.is_empty() {
                    data.push(' ');
                }
                data.push_str(&bytes);
            }
        }
        Ok(Some(::std::borrow::Cow::Owned(data)))
    }
}
impl xsd_parser_types::quick_xml::WithSerializeToBytes for EntitiesType {}
impl ::xsd_parser_types::quick_xml::DeserializeBytes for EntitiesType {
    fn deserialize_bytes(
        helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
        bytes: &[::core::primitive::u8],
    ) -> ::core::result::Result<Self, ::xsd_parser_types::quick_xml::Error> {
        Ok(Self(helper.deserialize_list(bytes)?))
    }
}
impl xsd_parser_types::quick_xml::WithDeserializerFromBytes for EntitiesType {}
pub type EntityType = ::std::string::String;
pub type IdType = ::std::string::String;
pub type IdrefType = ::std::string::String;
#[derive(Debug, Default)]
pub struct IdrefsType(pub ::std::vec::Vec<::std::string::String>);
impl ::xsd_parser_types::quick_xml::SerializeBytes for IdrefsType {
    fn serialize_bytes(
        &self,
        helper: &mut ::xsd_parser_types::quick_xml::SerializeHelper,
    ) -> ::core::result::Result<
        ::core::option::Option<::std::borrow::Cow<'_, ::core::primitive::str>>,
        ::xsd_parser_types::quick_xml::Error,
    > {
        if self.0.is_empty() {
            return Ok(None);
        }
        let mut data = ::std::string::String::new();
        for item in &self.0 {
            if let Some(bytes) = item.serialize_bytes(helper)? {
                if !data.is_empty() {
                    data.push(' ');
                }
                data.push_str(&bytes);
            }
        }
        Ok(Some(::std::borrow::Cow::Owned(data)))
    }
}
impl xsd_parser_types::quick_xml::WithSerializeToBytes for IdrefsType {}
impl ::xsd_parser_types::quick_xml::DeserializeBytes for IdrefsType {
    fn deserialize_bytes(
        helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
        bytes: &[::core::primitive::u8],
    ) -> ::core::result::Result<Self, ::xsd_parser_types::quick_xml::Error> {
        Ok(Self(helper.deserialize_list(bytes)?))
    }
}
impl xsd_parser_types::quick_xml::WithDeserializerFromBytes for IdrefsType {}
pub type NcNameType = ::std::string::String;
pub type NmtokenType = ::std::string::String;
#[derive(Debug, Default)]
pub struct NmtokensType(pub ::std::vec::Vec<::std::string::String>);
impl ::xsd_parser_types::quick_xml::SerializeBytes for NmtokensType {
    fn serialize_bytes(
        &self,
        helper: &mut ::xsd_parser_types::quick_xml::SerializeHelper,
    ) -> ::core::result::Result<
        ::core::option::Option<::std::borrow::Cow<'_, ::core::primitive::str>>,
        ::xsd_parser_types::quick_xml::Error,
    > {
        if self.0.is_empty() {
            return Ok(None);
        }
        let mut data = ::std::string::String::new();
        for item in &self.0 {
            if let Some(bytes) = item.serialize_bytes(helper)? {
                if !data.is_empty() {
                    data.push(' ');
                }
                data.push_str(&bytes);
            }
        }
        Ok(Some(::std::borrow::Cow::Owned(data)))
    }
}
impl xsd_parser_types::quick_xml::WithSerializeToBytes for NmtokensType {}
impl ::xsd_parser_types::quick_xml::DeserializeBytes for NmtokensType {
    fn deserialize_bytes(
        helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
        bytes: &[::core::primitive::u8],
    ) -> ::core::result::Result<Self, ::xsd_parser_types::quick_xml::Error> {
        Ok(Self(helper.deserialize_list(bytes)?))
    }
}
impl xsd_parser_types::quick_xml::WithDeserializerFromBytes for NmtokensType {}
pub type NotationType = ::std::string::String;
pub type NameType = ::std::string::String;
pub type QNameType = ::std::string::String;
pub type AnySimpleType = ::std::string::String;
#[derive(Debug)]
pub struct AnyType;
impl ::xsd_parser_types::quick_xml::WithSerializer for AnyType {
    type Serializer<'x> = quick_xml_serialize::AnyTypeSerializer<'x>;
    fn serializer<'ser>(
        &'ser self,
        name: ::core::option::Option<&'ser ::core::primitive::str>,
        is_root: ::core::primitive::bool,
    ) -> ::core::result::Result<Self::Serializer<'ser>, ::xsd_parser_types::quick_xml::Error> {
        Ok(quick_xml_serialize::AnyTypeSerializer {
            value: self,
            state: ::std::boxed::Box::new(quick_xml_serialize::AnyTypeSerializerState::Init__),
            name: name.unwrap_or("anyType"),
            is_root,
        })
    }
}
impl ::xsd_parser_types::quick_xml::WithDeserializer for AnyType {
    type Deserializer = quick_xml_deserialize::AnyTypeDeserializer;
}
pub type AnyUriType = ::std::string::String;
pub type Base64BinaryType = ::std::string::String;
pub type BooleanType = ::core::primitive::bool;
pub type ByteType = ::core::primitive::i8;
pub type DateType = ::std::string::String;
pub type DateTimeType = ::std::string::String;
pub type DecimalType = ::core::primitive::f64;
pub type DoubleType = ::core::primitive::f64;
pub type DurationType = ::std::string::String;
pub type FloatType = ::core::primitive::f32;
pub type GDayType = ::std::string::String;
pub type GMonthType = ::std::string::String;
pub type GMonthDayType = ::std::string::String;
pub type GYearType = ::std::string::String;
pub type GYearMonthType = ::std::string::String;
pub type HexBinaryType = ::std::string::String;
pub type IntType = ::core::primitive::i32;
pub type IntegerType = ::core::primitive::i32;
pub type LanguageType = ::std::string::String;
pub type LongType = ::core::primitive::i64;
pub type NegativeIntegerType = ::core::primitive::isize;
pub type NonNegativeIntegerType = ::core::primitive::usize;
pub type NonPositiveIntegerType = ::core::primitive::isize;
pub type NormalizedStringType = ::std::string::String;
pub type PositiveIntegerType = ::core::primitive::usize;
pub type ShortType = ::core::primitive::i16;
pub type StringType = ::std::string::String;
pub type TimeType = ::std::string::String;
pub type TokenType = ::std::string::String;
pub type UnsignedByteType = ::core::primitive::u8;
pub type UnsignedIntType = ::core::primitive::u32;
pub type UnsignedLongType = ::core::primitive::u64;
pub type UnsignedShortType = ::core::primitive::u16;
pub mod quick_xml_deserialize {
    use xsd_parser_types::quick_xml::Deserializer as _;
    #[derive(Debug)]
    pub struct AnyTypeDeserializer {
        state__: ::std::boxed::Box<AnyTypeDeserializerState>,
    }
    #[derive(Debug)]
    enum AnyTypeDeserializerState {
        Init__,
        Unknown__,
    }
    impl AnyTypeDeserializer {
        fn from_bytes_start(
            helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
            bytes_start: &::xsd_parser_types::quick_xml::BytesStart<'_>,
        ) -> ::core::result::Result<Self, ::xsd_parser_types::quick_xml::Error> {
            Ok(Self {
                state__: ::std::boxed::Box::new(AnyTypeDeserializerState::Init__),
            })
        }
        fn finish_state(
            &mut self,
            helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
            state: AnyTypeDeserializerState,
        ) -> ::core::result::Result<(), ::xsd_parser_types::quick_xml::Error> {
            Ok(())
        }
    }
    impl<'de> ::xsd_parser_types::quick_xml::Deserializer<'de, super::AnyType> for AnyTypeDeserializer {
        fn init(
            helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
            event: ::xsd_parser_types::quick_xml::Event<'de>,
        ) -> ::xsd_parser_types::quick_xml::DeserializerResult<'de, super::AnyType> {
            helper.init_deserializer_from_start_event(event, Self::from_bytes_start)
        }
        fn next(
            mut self,
            helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
            event: ::xsd_parser_types::quick_xml::Event<'de>,
        ) -> ::xsd_parser_types::quick_xml::DeserializerResult<'de, super::AnyType> {
            if let ::xsd_parser_types::quick_xml::Event::End(_) = &event {
                Ok(::xsd_parser_types::quick_xml::DeserializerOutput {
                    artifact: ::xsd_parser_types::quick_xml::DeserializerArtifact::Data(
                        self.finish(helper)?,
                    ),
                    event: ::xsd_parser_types::quick_xml::DeserializerEvent::None,
                    allow_any: false,
                })
            } else if matches!(
                &event,
                ::xsd_parser_types::quick_xml::Event::Text(_)
                    | ::xsd_parser_types::quick_xml::Event::CData(_)
            ) {
                Ok(::xsd_parser_types::quick_xml::DeserializerOutput {
                    artifact: ::xsd_parser_types::quick_xml::DeserializerArtifact::Deserializer(
                        self,
                    ),
                    event: ::xsd_parser_types::quick_xml::DeserializerEvent::None,
                    allow_any: true,
                })
            } else {
                Ok(::xsd_parser_types::quick_xml::DeserializerOutput {
                    artifact: ::xsd_parser_types::quick_xml::DeserializerArtifact::Deserializer(
                        self,
                    ),
                    event: ::xsd_parser_types::quick_xml::DeserializerEvent::Break(event),
                    allow_any: true,
                })
            }
        }
        fn finish(
            mut self,
            helper: &mut ::xsd_parser_types::quick_xml::DeserializeHelper,
        ) -> ::core::result::Result<super::AnyType, ::xsd_parser_types::quick_xml::Error> {
            let state =
                ::core::mem::replace(&mut *self.state__, AnyTypeDeserializerState::Unknown__);
            self.finish_state(helper, state)?;
            Ok(super::AnyType {})
        }
    }
}
pub mod quick_xml_serialize {
    use xsd_parser_types::quick_xml::Serializer as _;
    #[derive(Debug)]
    pub struct AnyTypeSerializer<'ser> {
        pub(super) value: &'ser super::AnyType,
        pub(super) state: ::std::boxed::Box<AnyTypeSerializerState<'ser>>,
        pub(super) name: &'ser ::core::primitive::str,
        pub(super) is_root: ::core::primitive::bool,
    }
    #[derive(Debug)]
    pub(super) enum AnyTypeSerializerState<'ser> {
        Init__,
        Done__,
        Phantom__(&'ser ()),
    }
    impl<'ser> AnyTypeSerializer<'ser> {
        fn next_event(
            &mut self,
            helper: &mut ::xsd_parser_types::quick_xml::SerializeHelper,
        ) -> ::core::result::Result<
            ::core::option::Option<::xsd_parser_types::quick_xml::Event<'ser>>,
            ::xsd_parser_types::quick_xml::Error,
        > {
            loop {
                match &mut *self.state {
                    AnyTypeSerializerState::Init__ => {
                        *self.state = AnyTypeSerializerState::Done__;
                        let bytes = ::xsd_parser_types::quick_xml::BytesStart::new(self.name);
                        return Ok(Some(::xsd_parser_types::quick_xml::Event::Empty(bytes)));
                    }
                    AnyTypeSerializerState::Done__ => return Ok(None),
                    AnyTypeSerializerState::Phantom__(_) => unreachable!(),
                }
            }
        }
    }
    impl<'ser> ::xsd_parser_types::quick_xml::Serializer<'ser> for AnyTypeSerializer<'ser> {
        fn next(
            &mut self,
            helper: &mut ::xsd_parser_types::quick_xml::SerializeHelper,
        ) -> ::core::option::Option<
            ::core::result::Result<
                ::xsd_parser_types::quick_xml::Event<'ser>,
                ::xsd_parser_types::quick_xml::Error,
            >,
        > {
            match self.next_event(helper) {
                Ok(Some(event)) => Some(Ok(event)),
                Ok(None) => None,
                Err(error) => {
                    *self.state = AnyTypeSerializerState::Done__;
                    Some(Err(error))
                }
            }
        }
    }
}