datex2 0.1.0

Unofficial DATEX II implementation in Rust: read, stream and write road traffic and travel information (v3 XML) as typed data.
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
// @generated by `cargo xtask codegen` from the DATEX II 3.7 schemas. Do not edit.
//! Types of the DATEX II namespace `http://datex2.eu/schema/3/urbanExtensions`.
//!
//! Names follow the standard; see <https://docs.datex2.eu/> for what each one means.

#[allow(unused_imports)]
use super::{common as com, common_extension as comx, location_referencing as loc, location_extension as locx, situation as sit, road_traffic_data as roa, vms, parking as prk, energy_infrastructure as egi, afir_energy_infrastructure as aegi, facilities as fac, afir_facilities as afac, traffic_regulation as tro, controlled_zone as cz, traffic_management_plan as tmp, rerouting_management_enhanced as rer, fault_and_status as fst};
#[allow(unused_imports)]
use crate::out::{Out, Pattern};
#[allow(unused_imports)]
use crate::xml::{Enumeration, Xml};
#[allow(unused_imports)]
use crate::{Date, DateTime, Decimal, Error, Extension, MultilingualString, Time};

/// XML enumeration `ubx:NonVehicularRoadUserTypeEnum`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NonVehicularRoadUserTypeEnum {
    /// `pedestrian`
    Pedestrian,
    /// `skater`
    Skater,
    /// `animalUnderGuidance`
    AnimalUnderGuidance,
    /// `other`
    Other,
    /// A value outside the standard list.
    Extended(String),
}

impl NonVehicularRoadUserTypeEnum {
    /// The value as written in a document.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Pedestrian => "pedestrian",
            Self::Skater => "skater",
            Self::AnimalUnderGuidance => "animalUnderGuidance",
            Self::Other => "other",
            Self::Extended(v) => v,
        }
    }
}

impl Enumeration for NonVehicularRoadUserTypeEnum {
    fn from_literal(literal: &str) -> Option<Self> {
        match literal {
            "pedestrian" => Some(Self::Pedestrian),
            "skater" => Some(Self::Skater),
            "animalUnderGuidance" => Some(Self::AnimalUnderGuidance),
            "other" => Some(Self::Other),
            _ => None,
        }
    }

    fn extended(value: String) -> Self {
        Self::Extended(value)
    }
}

impl NonVehicularRoadUserTypeEnum {
    /// The literal to write and, for a value outside the standard list, that value.
    #[allow(unreachable_patterns)]
    pub(crate) fn literal(&self) -> (&str, Option<&str>) {
        match self {
            Self::Extended(v) => ("_extended", Some(v)),
            other => (other.as_str(), None),
        }
    }
}

/// XML enumeration `ubx:StreetWorksTypeEnum`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StreetWorksTypeEnum {
    /// `buildingWork`
    BuildingWork,
    /// `trenchingWork`
    TrenchingWork,
    /// `utilityWork`
    UtilityWork,
    /// A value outside the standard list.
    Extended(String),
}

impl StreetWorksTypeEnum {
    /// The value as written in a document.
    pub fn as_str(&self) -> &str {
        match self {
            Self::BuildingWork => "buildingWork",
            Self::TrenchingWork => "trenchingWork",
            Self::UtilityWork => "utilityWork",
            Self::Extended(v) => v,
        }
    }
}

impl Enumeration for StreetWorksTypeEnum {
    fn from_literal(literal: &str) -> Option<Self> {
        match literal {
            "buildingWork" => Some(Self::BuildingWork),
            "trenchingWork" => Some(Self::TrenchingWork),
            "utilityWork" => Some(Self::UtilityWork),
            _ => None,
        }
    }

    fn extended(value: String) -> Self {
        Self::Extended(value)
    }
}

impl StreetWorksTypeEnum {
    /// The literal to write and, for a value outside the standard list, that value.
    #[allow(unreachable_patterns)]
    pub(crate) fn literal(&self) -> (&str, Option<&str>) {
        match self {
            Self::Extended(v) => ("_extended", Some(v)),
            other => (other.as_str(), None),
        }
    }
}

/// XML type `ubx:AccidentExtendedUrban`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct AccidentExtendedUrban {
    /// XML element `ubx:groupOfNonVehicularRoadUsersInvolved`.
    pub group_of_non_vehicular_road_users_involved: Vec<GroupOfNonVehicularRoadUsersInvolved>,
}

impl AccidentExtendedUrban {
    const FIELDS: &'static [u32] = &[0x12084e];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0x12000a);
        r.attrs_done();
        let mut e0 = Vec::new();
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0x12084e => { let v = Some(GroupOfNonVehicularRoadUsersInvolved::read(r)?); e0.extend(v); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        let v = Self {
            group_of_non_vehicular_road_users_involved: e0,
        };
        r.close();
        Ok(v)
    }
}

impl AccidentExtendedUrban {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        for v in &self.group_of_non_vehicular_road_users_involved { v.write(w, "ubx:groupOfNonVehicularRoadUsersInvolved", "", "")?; }
        w.end(tag)
    }
}

/// XML type `ubx:ClassifiedDelay`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ClassifiedDelay {
    /// XML element `ubx:delays`.
    pub delays: Option<Box<sit::Delays>>,
    /// XML element `ubx:vehicleCharacteristics`.
    pub vehicle_characteristics: Option<Box<com::VehicleCharacteristics>>,
    /// XML element `ubx:_classifiedDelayExtension`.
    pub classified_delay_extension: Option<Box<Extension>>,
}

impl ClassifiedDelay {
    const FIELDS: &'static [u32] = &[0x12076b, 0x120c30, 0x12043a];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0x12004e);
        r.attrs_done();
        let mut e0 = None;
        let mut e1 = None;
        let mut e2 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0x12076b => { let v = Some(sit::Delays::read(r)?); r.set(&mut e0, v.map(Box::new), 1899); }
                    0x120c30 => { let v = Some(com::VehicleCharacteristics::read(r)?); r.set(&mut e1, v.map(Box::new), 3120); }
                    0x12043a => { let v = r.raw()?; r.set(&mut e2, v.map(Box::new), 1082); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        r.required(&e0, 1899);
        r.required(&e1, 3120);
        let v = Self {
            delays: e0,
            vehicle_characteristics: e1,
            classified_delay_extension: e2,
        };
        r.close();
        Ok(v)
    }
}

impl ClassifiedDelay {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        match &self.delays {
            Some(v) => { v.write(w, "ubx:delays", "", "")?; }
            None => return Err(w.missing("ubx:delays")),
        }
        match &self.vehicle_characteristics {
            Some(v) => { v.write(w, "ubx:vehicleCharacteristics", "", "")?; }
            None => return Err(w.missing("ubx:vehicleCharacteristics")),
        }
        if let Some(v) = &self.classified_delay_extension { w.extension("ubx:_classifiedDelayExtension", v)?; }
        w.end(tag)
    }
}

/// XML type `ubx:GroupOfNonVehicularRoadUsersInvolved`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GroupOfNonVehicularRoadUsersInvolved {
    /// XML element `ubx:numberOfNonVehicularRoadUsers`.
    pub number_of_non_vehicular_road_users: Option<com::NonNegativeInteger>,
    /// XML element `ubx:injuryStatusType`.
    pub injury_status_type: Option<sit::InjuryStatusTypeEnum>,
    /// XML element `ubx:nonVehicularRoadUsers`.
    pub non_vehicular_road_users: Option<Box<NonVehicularRoadUsers>>,
    /// XML element `ubx:_groupOfNonVehicularRoadUsersInvolvedExtension`.
    pub group_of_non_vehicular_road_users_involved_extension: Option<Box<Extension>>,
}

impl GroupOfNonVehicularRoadUsersInvolved {
    const FIELDS: &'static [u32] = &[0x120979, 0x12088a, 0x120968, 0x1204b5];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0x1200cb);
        r.attrs_done();
        let mut e0 = None;
        let mut e1 = None;
        let mut e2 = None;
        let mut e3 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0x120979 => { let v = r.value::<u64>()?; r.set(&mut e0, v, 2425); }
                    0x12088a => { let v = r.enumeration::<sit::InjuryStatusTypeEnum>()?; r.set(&mut e1, v, 2186); }
                    0x120968 => { let v = Some(NonVehicularRoadUsers::read(r)?); r.set(&mut e2, v.map(Box::new), 2408); }
                    0x1204b5 => { let v = r.raw()?; r.set(&mut e3, v.map(Box::new), 1205); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        let v = Self {
            number_of_non_vehicular_road_users: e0,
            injury_status_type: e1,
            non_vehicular_road_users: e2,
            group_of_non_vehicular_road_users_involved_extension: e3,
        };
        r.close();
        Ok(v)
    }
}

impl GroupOfNonVehicularRoadUsersInvolved {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        if let Some(v) = &self.number_of_non_vehicular_road_users { w.leaf("ubx:numberOfNonVehicularRoadUsers", v)?; }
        if let Some(v) = &self.injury_status_type { w.enumeration("ubx:injuryStatusType", v.literal())?; }
        if let Some(v) = &self.non_vehicular_road_users { v.write(w, "ubx:nonVehicularRoadUsers", "", "")?; }
        if let Some(v) = &self.group_of_non_vehicular_road_users_involved_extension { w.extension("ubx:_groupOfNonVehicularRoadUsersInvolvedExtension", v)?; }
        w.end(tag)
    }
}

/// XML type `ubx:ImpactExtendedUrban`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ImpactExtendedUrban {
    /// XML element `ubx:classifiedDelay`.
    pub classified_delay: Vec<ClassifiedDelay>,
}

impl ImpactExtendedUrban {
    const FIELDS: &'static [u32] = &[0x12071b];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0x1200dd);
        r.attrs_done();
        let mut e0 = Vec::new();
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0x12071b => { let v = Some(ClassifiedDelay::read(r)?); e0.extend(v); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        let v = Self {
            classified_delay: e0,
        };
        r.close();
        Ok(v)
    }
}

impl ImpactExtendedUrban {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        for v in &self.classified_delay { v.write(w, "ubx:classifiedDelay", "", "")?; }
        w.end(tag)
    }
}

/// XML type `ubx:NetworkManagementExtendedUrban`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct NetworkManagementExtendedUrban {
    /// XML element `ubx:forNonMotorisedRoadUsers`.
    pub for_non_motorised_road_users: Option<Box<NonVehicularRoadUsers>>,
}

impl NetworkManagementExtendedUrban {
    const FIELDS: &'static [u32] = &[0x120826];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0x120118);
        r.attrs_done();
        let mut e0 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0x120826 => { let v = Some(NonVehicularRoadUsers::read(r)?); r.set(&mut e0, v.map(Box::new), 2086); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        let v = Self {
            for_non_motorised_road_users: e0,
        };
        r.close();
        Ok(v)
    }
}

impl NetworkManagementExtendedUrban {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        if let Some(v) = &self.for_non_motorised_road_users { v.write(w, "ubx:forNonMotorisedRoadUsers", "", "")?; }
        w.end(tag)
    }
}

/// XML type `ubx:NonVehicularRoadUsers`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct NonVehicularRoadUsers {
    /// XML element `ubx:nonVehicularRoadUser`.
    pub non_vehicular_road_user: Vec<NonVehicularRoadUserTypeEnum>,
    /// XML element `ubx:_nonVehicularRoadUsersExtension`.
    pub non_vehicular_road_users_extension: Option<Box<Extension>>,
}

impl NonVehicularRoadUsers {
    const FIELDS: &'static [u32] = &[0x120967, 0x120504];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0x12011f);
        r.attrs_done();
        let mut e0 = Vec::new();
        let mut e1 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0x120967 => { let v = r.enumeration::<NonVehicularRoadUserTypeEnum>()?; e0.extend(v); }
                    0x120504 => { let v = r.raw()?; r.set(&mut e1, v.map(Box::new), 1284); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        let v = Self {
            non_vehicular_road_user: e0,
            non_vehicular_road_users_extension: e1,
        };
        r.close();
        Ok(v)
    }
}

impl NonVehicularRoadUsers {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        w.count("ubx:nonVehicularRoadUser", self.non_vehicular_road_user.len(), 1, usize::MAX)?;
        for v in &self.non_vehicular_road_user { w.enumeration("ubx:nonVehicularRoadUser", v.literal())?; }
        if let Some(v) = &self.non_vehicular_road_users_extension { w.extension("ubx:_nonVehicularRoadUsersExtension", v)?; }
        w.end(tag)
    }
}

/// XML type `ubx:StreetWorks`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct StreetWorks {
    /// XML element `ubx:streetWorksType`.
    pub street_works_type: Option<StreetWorksTypeEnum>,
}

impl StreetWorks {
    const FIELDS: &'static [u32] = &[0x120b84];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0x1201f9);
        r.attrs_done();
        let mut e0 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0x120b84 => { let v = r.enumeration::<StreetWorksTypeEnum>()?; r.set(&mut e0, v, 2948); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        r.required(&e0, 2948);
        let v = Self {
            street_works_type: e0,
        };
        r.close();
        Ok(v)
    }
}

impl StreetWorks {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        match &self.street_works_type {
            Some(v) => { w.enumeration("ubx:streetWorksType", v.literal())?; }
            None => return Err(w.missing("ubx:streetWorksType")),
        }
        w.end(tag)
    }
}