osmflat/
osmflat_generated.rs

1// Do not edit: This code was generated by flatdata's generator.
2#[allow(missing_docs)]
3pub mod osm {
4#[allow(unused_imports)]
5use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
6
7
8    /// Special value which represents an invalid index.
9pub const INVALID_IDX: u64 = 1_099_511_627_775;
10/// Metadata attached to the archive.
11#[repr(transparent)]
12#[derive(Clone)]
13pub struct Header {
14    data: [u8; 51],
15}
16
17impl Header {
18    /// Unsafe since the struct might not be self-contained
19    pub unsafe fn new_unchecked( ) -> Self {
20        Self{data : [0; 51]}
21    }
22}
23
24impl flatdata::Struct for Header {
25    unsafe fn create_unchecked( ) -> Self {
26        Self{data : [0; 51]}
27    }
28
29    const SIZE_IN_BYTES: usize = 51;
30    const IS_OVERLAPPING_WITH_NEXT : bool = false;
31}
32
33impl Header {
34    pub fn new( ) -> Self {
35        Self{data : [0; 51]}
36    }
37
38    /// Create reference from byte array of matching size
39    pub fn from_bytes(data: &[u8; 51]) -> &Self {
40        // Safety: This is safe since Header is repr(transparent)
41        unsafe{ std::mem::transmute( data ) }
42    }
43
44    /// Create reference from byte array of matching size
45    pub fn from_bytes_mut(data: &mut [u8; 51]) -> &mut Self {
46        // Safety: This is safe since Header is repr(transparent)
47        unsafe{ std::mem::transmute( data ) }
48    }
49
50    /// Create reference from byte array
51    pub fn from_bytes_slice(data: &[u8]) -> Result<&Self, flatdata::ResourceStorageError> {
52        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
53        if data.len() < 51 {
54            assert_eq!(data.len(), 51);
55            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
56        }
57        let ptr = data.as_ptr() as *const [u8; 51];
58        // Safety: We checked length before
59        Ok(Self::from_bytes(unsafe { &*ptr }))
60    }
61
62    /// Create reference from byte array
63    pub fn from_bytes_slice_mut(data: &mut [u8]) -> Result<&mut Self, flatdata::ResourceStorageError> {
64        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
65        if data.len() < 51 {
66            assert_eq!(data.len(), 51);
67            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
68        }
69        let ptr = data.as_ptr() as *mut [u8; 51];
70        // Safety: We checked length before
71        Ok(Self::from_bytes_mut(unsafe { &mut *ptr }))
72    }
73
74    pub fn as_bytes(&self) -> &[u8; 51] {
75        &self.data
76    }
77}
78
79impl Default for Header {
80    fn default( ) -> Self {
81        Self::new( )
82    }
83}
84
85unsafe impl flatdata::NoOverlap for Header {}
86
87impl Header {
88    /// All coordinates in this archive are scaled by this constant
89/// To get the original degree-based coordinate back compute (latitude/coord_scale,longitude/coord_scale)
90    #[inline]
91    pub fn coord_scale(&self) -> i32 {
92        let value = flatdata_read_bytes!(i32, self.data.as_ptr(), 0, 32);
93        unsafe { std::mem::transmute::<i32, i32>(value) }
94    }
95
96    /// Bounding box (min longitude scaled with `header.coord_scale`)
97    #[inline]
98    pub fn bbox_left(&self) -> i32 {
99        let value = flatdata_read_bytes!(i32, self.data.as_ptr(), 32, 32);
100        unsafe { std::mem::transmute::<i32, i32>(value) }
101    }
102
103    /// Bounding box (max longitude scaled with `header.coord_scale`)
104    #[inline]
105    pub fn bbox_right(&self) -> i32 {
106        let value = flatdata_read_bytes!(i32, self.data.as_ptr(), 64, 32);
107        unsafe { std::mem::transmute::<i32, i32>(value) }
108    }
109
110    /// Bounding box (max latitude scaled with `header.coord_scale`)
111    #[inline]
112    pub fn bbox_top(&self) -> i32 {
113        let value = flatdata_read_bytes!(i32, self.data.as_ptr(), 96, 32);
114        unsafe { std::mem::transmute::<i32, i32>(value) }
115    }
116
117    /// Bounding box (min latitude scaled with `header.coord_scale`)
118    #[inline]
119    pub fn bbox_bottom(&self) -> i32 {
120        let value = flatdata_read_bytes!(i32, self.data.as_ptr(), 128, 32);
121        unsafe { std::mem::transmute::<i32, i32>(value) }
122    }
123
124    /// Writing program used to write the data (reference to `stringtable`).
125    #[inline]
126    pub fn writingprogram_idx(&self) -> u64 {
127        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 160, 40);
128        unsafe { std::mem::transmute::<u64, u64>(value) }
129    }
130
131    /// The origin (source) of the data.
132    #[inline]
133    pub fn source_idx(&self) -> u64 {
134        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 200, 40);
135        unsafe { std::mem::transmute::<u64, u64>(value) }
136    }
137
138    /// Replication timestamp, expressed in seconds since the epoch.
139/// See [`state.txt`].
140///
141/// [`state.txt`]: https://wiki.openstreetmap.org/wiki/Planet.osm/diffs#Minute.2C_Hour.2C_and_Day_Files_Organisation
142    #[inline]
143    pub fn replication_timestamp(&self) -> i64 {
144        let value = flatdata_read_bytes!(i64, self.data.as_ptr(), 240, 64);
145        unsafe { std::mem::transmute::<i64, i64>(value) }
146    }
147
148    /// Replication sequence number (`sequenceNumber` from [`state.txt`]).
149///
150/// [`state.txt`]: https://wiki.openstreetmap.org/wiki/Planet.osm/diffs#Minute.2C_Hour.2C_and_Day_Files_Organisation
151    #[inline]
152    pub fn replication_sequence_number(&self) -> i64 {
153        let value = flatdata_read_bytes!(i64, self.data.as_ptr(), 304, 64);
154        unsafe { std::mem::transmute::<i64, i64>(value) }
155    }
156
157    /// Replication base URL (reference to `stringtable`).
158    #[inline]
159    pub fn replication_base_url_idx(&self) -> u64 {
160        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 368, 40);
161        unsafe { std::mem::transmute::<u64, u64>(value) }
162    }
163
164}
165
166impl std::fmt::Debug for Header {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.debug_struct("Header")
169            .field("coord_scale", &self.coord_scale())
170            .field("bbox_left", &self.bbox_left())
171            .field("bbox_right", &self.bbox_right())
172            .field("bbox_top", &self.bbox_top())
173            .field("bbox_bottom", &self.bbox_bottom())
174            .field("writingprogram_idx", &self.writingprogram_idx())
175            .field("source_idx", &self.source_idx())
176            .field("replication_timestamp", &self.replication_timestamp())
177            .field("replication_sequence_number", &self.replication_sequence_number())
178            .field("replication_base_url_idx", &self.replication_base_url_idx())
179            .finish()
180    }
181}
182
183impl std::cmp::PartialEq for Header {
184    #[inline]
185    fn eq(&self, other: &Self) -> bool {
186        self.coord_scale() == other.coord_scale() &&        self.bbox_left() == other.bbox_left() &&        self.bbox_right() == other.bbox_right() &&        self.bbox_top() == other.bbox_top() &&        self.bbox_bottom() == other.bbox_bottom() &&        self.writingprogram_idx() == other.writingprogram_idx() &&        self.source_idx() == other.source_idx() &&        self.replication_timestamp() == other.replication_timestamp() &&        self.replication_sequence_number() == other.replication_sequence_number() &&        self.replication_base_url_idx() == other.replication_base_url_idx()     }
187}
188
189impl Header {
190    /// All coordinates in this archive are scaled by this constant
191/// To get the original degree-based coordinate back compute (latitude/coord_scale,longitude/coord_scale)
192    #[inline]
193    #[allow(missing_docs)]
194    pub fn set_coord_scale(&mut self, value: i32) {
195        flatdata_write_bytes!(i32; value, self.data, 0, 32)
196    }
197
198    /// Bounding box (min longitude scaled with `header.coord_scale`)
199    #[inline]
200    #[allow(missing_docs)]
201    pub fn set_bbox_left(&mut self, value: i32) {
202        flatdata_write_bytes!(i32; value, self.data, 32, 32)
203    }
204
205    /// Bounding box (max longitude scaled with `header.coord_scale`)
206    #[inline]
207    #[allow(missing_docs)]
208    pub fn set_bbox_right(&mut self, value: i32) {
209        flatdata_write_bytes!(i32; value, self.data, 64, 32)
210    }
211
212    /// Bounding box (max latitude scaled with `header.coord_scale`)
213    #[inline]
214    #[allow(missing_docs)]
215    pub fn set_bbox_top(&mut self, value: i32) {
216        flatdata_write_bytes!(i32; value, self.data, 96, 32)
217    }
218
219    /// Bounding box (min latitude scaled with `header.coord_scale`)
220    #[inline]
221    #[allow(missing_docs)]
222    pub fn set_bbox_bottom(&mut self, value: i32) {
223        flatdata_write_bytes!(i32; value, self.data, 128, 32)
224    }
225
226    /// Writing program used to write the data (reference to `stringtable`).
227    #[inline]
228    #[allow(missing_docs)]
229    pub fn set_writingprogram_idx(&mut self, value: u64) {
230        flatdata_write_bytes!(u64; value, self.data, 160, 40)
231    }
232
233    /// The origin (source) of the data.
234    #[inline]
235    #[allow(missing_docs)]
236    pub fn set_source_idx(&mut self, value: u64) {
237        flatdata_write_bytes!(u64; value, self.data, 200, 40)
238    }
239
240    /// Replication timestamp, expressed in seconds since the epoch.
241/// See [`state.txt`].
242///
243/// [`state.txt`]: https://wiki.openstreetmap.org/wiki/Planet.osm/diffs#Minute.2C_Hour.2C_and_Day_Files_Organisation
244    #[inline]
245    #[allow(missing_docs)]
246    pub fn set_replication_timestamp(&mut self, value: i64) {
247        flatdata_write_bytes!(i64; value, self.data, 240, 64)
248    }
249
250    /// Replication sequence number (`sequenceNumber` from [`state.txt`]).
251///
252/// [`state.txt`]: https://wiki.openstreetmap.org/wiki/Planet.osm/diffs#Minute.2C_Hour.2C_and_Day_Files_Organisation
253    #[inline]
254    #[allow(missing_docs)]
255    pub fn set_replication_sequence_number(&mut self, value: i64) {
256        flatdata_write_bytes!(i64; value, self.data, 304, 64)
257    }
258
259    /// Replication base URL (reference to `stringtable`).
260    #[inline]
261    #[allow(missing_docs)]
262    pub fn set_replication_base_url_idx(&mut self, value: u64) {
263        flatdata_write_bytes!(u64; value, self.data, 368, 40)
264    }
265
266
267    /// Copies the data from `other` into this struct.
268    #[inline]
269    pub fn fill_from(&mut self, other: &Header) {
270        self.set_coord_scale(other.coord_scale());
271        self.set_bbox_left(other.bbox_left());
272        self.set_bbox_right(other.bbox_right());
273        self.set_bbox_top(other.bbox_top());
274        self.set_bbox_bottom(other.bbox_bottom());
275        self.set_writingprogram_idx(other.writingprogram_idx());
276        self.set_source_idx(other.source_idx());
277        self.set_replication_timestamp(other.replication_timestamp());
278        self.set_replication_sequence_number(other.replication_sequence_number());
279        self.set_replication_base_url_idx(other.replication_base_url_idx());
280    }
281}
282/// A `(key, value)` attached to a `Node`, `Way`, or `Relation.
283#[repr(transparent)]
284#[derive(Clone)]
285pub struct Tag {
286    data: [u8; 10],
287}
288
289impl Tag {
290    /// Unsafe since the struct might not be self-contained
291    pub unsafe fn new_unchecked( ) -> Self {
292        Self{data : [0; 10]}
293    }
294}
295
296impl flatdata::Struct for Tag {
297    unsafe fn create_unchecked( ) -> Self {
298        Self{data : [0; 10]}
299    }
300
301    const SIZE_IN_BYTES: usize = 10;
302    const IS_OVERLAPPING_WITH_NEXT : bool = false;
303}
304
305impl Tag {
306    pub fn new( ) -> Self {
307        Self{data : [0; 10]}
308    }
309
310    /// Create reference from byte array of matching size
311    pub fn from_bytes(data: &[u8; 10]) -> &Self {
312        // Safety: This is safe since Tag is repr(transparent)
313        unsafe{ std::mem::transmute( data ) }
314    }
315
316    /// Create reference from byte array of matching size
317    pub fn from_bytes_mut(data: &mut [u8; 10]) -> &mut Self {
318        // Safety: This is safe since Tag is repr(transparent)
319        unsafe{ std::mem::transmute( data ) }
320    }
321
322    /// Create reference from byte array
323    pub fn from_bytes_slice(data: &[u8]) -> Result<&Self, flatdata::ResourceStorageError> {
324        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
325        if data.len() < 10 {
326            assert_eq!(data.len(), 10);
327            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
328        }
329        let ptr = data.as_ptr() as *const [u8; 10];
330        // Safety: We checked length before
331        Ok(Self::from_bytes(unsafe { &*ptr }))
332    }
333
334    /// Create reference from byte array
335    pub fn from_bytes_slice_mut(data: &mut [u8]) -> Result<&mut Self, flatdata::ResourceStorageError> {
336        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
337        if data.len() < 10 {
338            assert_eq!(data.len(), 10);
339            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
340        }
341        let ptr = data.as_ptr() as *mut [u8; 10];
342        // Safety: We checked length before
343        Ok(Self::from_bytes_mut(unsafe { &mut *ptr }))
344    }
345
346    pub fn as_bytes(&self) -> &[u8; 10] {
347        &self.data
348    }
349}
350
351impl Default for Tag {
352    fn default( ) -> Self {
353        Self::new( )
354    }
355}
356
357unsafe impl flatdata::NoOverlap for Tag {}
358
359impl Tag {
360    /// Key index in `stringtable`
361    #[inline]
362    pub fn key_idx(&self) -> u64 {
363        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
364        unsafe { std::mem::transmute::<u64, u64>(value) }
365    }
366
367    /// Value index in `stringtable`
368    #[inline]
369    pub fn value_idx(&self) -> u64 {
370        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 40, 40);
371        unsafe { std::mem::transmute::<u64, u64>(value) }
372    }
373
374}
375
376impl std::fmt::Debug for Tag {
377    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
378        f.debug_struct("Tag")
379            .field("key_idx", &self.key_idx())
380            .field("value_idx", &self.value_idx())
381            .finish()
382    }
383}
384
385impl std::cmp::PartialEq for Tag {
386    #[inline]
387    fn eq(&self, other: &Self) -> bool {
388        self.key_idx() == other.key_idx() &&        self.value_idx() == other.value_idx()     }
389}
390
391impl Tag {
392    /// Key index in `stringtable`
393    #[inline]
394    #[allow(missing_docs)]
395    pub fn set_key_idx(&mut self, value: u64) {
396        flatdata_write_bytes!(u64; value, self.data, 0, 40)
397    }
398
399    /// Value index in `stringtable`
400    #[inline]
401    #[allow(missing_docs)]
402    pub fn set_value_idx(&mut self, value: u64) {
403        flatdata_write_bytes!(u64; value, self.data, 40, 40)
404    }
405
406
407    /// Copies the data from `other` into this struct.
408    #[inline]
409    pub fn fill_from(&mut self, other: &Tag) {
410        self.set_key_idx(other.key_idx());
411        self.set_value_idx(other.value_idx());
412    }
413}
414/// A node is one of the core elements in the OpenStreetMap data model.
415///
416/// It consists of a single point in space defined by its latitude, longitude and node id.
417///
418/// See <https://wiki.openstreetmap.org/wiki/Node>.
419#[repr(transparent)]
420pub struct Node {
421    data: [u8; 13],
422}
423
424impl Node {
425    /// Unsafe since the struct might not be self-contained
426    pub unsafe fn new_unchecked( ) -> Self {
427        Self{data : [0; 13]}
428    }
429}
430
431impl flatdata::Struct for Node {
432    unsafe fn create_unchecked( ) -> Self {
433        Self{data : [0; 13]}
434    }
435
436    const SIZE_IN_BYTES: usize = 13;
437    const IS_OVERLAPPING_WITH_NEXT : bool = true;
438}
439
440impl flatdata::Overlap for Node {}
441
442impl Node {
443    /// Latitude (scaled with `header.coord_scale`).
444    #[inline]
445    pub fn lat(&self) -> i32 {
446        let value = flatdata_read_bytes!(i32, self.data.as_ptr(), 0, 32);
447        unsafe { std::mem::transmute::<i32, i32>(value) }
448    }
449
450    /// Longitude (scaled with `header.coord_scale`).
451    #[inline]
452    pub fn lon(&self) -> i32 {
453        let value = flatdata_read_bytes!(i32, self.data.as_ptr(), 32, 32);
454        unsafe { std::mem::transmute::<i32, i32>(value) }
455    }
456
457    /// First element of the range [`tags`].
458    ///
459    /// [`tags`]: #method.tags
460    #[inline]
461    pub fn tag_first_idx(&self) -> u64 {
462        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 64, 40);
463        unsafe { std::mem::transmute::<u64, u64>(value) }
464    }
465
466    /// Range of tags attached to this node.
467///
468/// The values of the range are indexes in the `tags_index` vector.
469    #[inline]
470    pub fn tags(&self) -> std::ops::Range<u64> {
471        let start = flatdata_read_bytes!(u64, self.data.as_ptr(), 64, 40);
472        let end = flatdata_read_bytes!(u64, self.data.as_ptr(), 64 + 13 * 8, 40);
473        start..end
474    }
475
476}
477
478impl std::fmt::Debug for Node {
479    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
480        f.debug_struct("Node")
481            .field("lat", &self.lat())
482            .field("lon", &self.lon())
483            .field("tag_first_idx", &self.tag_first_idx())
484            .finish()
485    }
486}
487
488impl std::cmp::PartialEq for Node {
489    #[inline]
490    fn eq(&self, other: &Self) -> bool {
491        self.lat() == other.lat() &&        self.lon() == other.lon() &&        self.tag_first_idx() == other.tag_first_idx()     }
492}
493
494impl Node {
495    /// Latitude (scaled with `header.coord_scale`).
496    #[inline]
497    #[allow(missing_docs)]
498    pub fn set_lat(&mut self, value: i32) {
499        flatdata_write_bytes!(i32; value, self.data, 0, 32)
500    }
501
502    /// Longitude (scaled with `header.coord_scale`).
503    #[inline]
504    #[allow(missing_docs)]
505    pub fn set_lon(&mut self, value: i32) {
506        flatdata_write_bytes!(i32; value, self.data, 32, 32)
507    }
508
509    /// First element of the range [`tags`].
510    ///
511    /// [`tags`]: struct.NodeRef.html#method.tags
512    #[inline]
513    #[allow(missing_docs)]
514    pub fn set_tag_first_idx(&mut self, value: u64) {
515        flatdata_write_bytes!(u64; value, self.data, 64, 40)
516    }
517
518
519    /// Copies the data from `other` into this struct.
520    #[inline]
521    pub fn fill_from(&mut self, other: &Node) {
522        self.set_lat(other.lat());
523        self.set_lon(other.lon());
524        self.set_tag_first_idx(other.tag_first_idx());
525    }
526}
527/// Index of a node.
528#[repr(transparent)]
529#[derive(Clone)]
530pub struct NodeIndex {
531    data: [u8; 5],
532}
533
534impl NodeIndex {
535    /// Unsafe since the struct might not be self-contained
536    pub unsafe fn new_unchecked( ) -> Self {
537        Self{data : [0; 5]}
538    }
539}
540
541impl flatdata::Struct for NodeIndex {
542    unsafe fn create_unchecked( ) -> Self {
543        Self{data : [0; 5]}
544    }
545
546    const SIZE_IN_BYTES: usize = 5;
547    const IS_OVERLAPPING_WITH_NEXT : bool = false;
548}
549
550impl NodeIndex {
551    pub fn new( ) -> Self {
552        Self{data : [0; 5]}
553    }
554
555    /// Create reference from byte array of matching size
556    pub fn from_bytes(data: &[u8; 5]) -> &Self {
557        // Safety: This is safe since NodeIndex is repr(transparent)
558        unsafe{ std::mem::transmute( data ) }
559    }
560
561    /// Create reference from byte array of matching size
562    pub fn from_bytes_mut(data: &mut [u8; 5]) -> &mut Self {
563        // Safety: This is safe since NodeIndex is repr(transparent)
564        unsafe{ std::mem::transmute( data ) }
565    }
566
567    /// Create reference from byte array
568    pub fn from_bytes_slice(data: &[u8]) -> Result<&Self, flatdata::ResourceStorageError> {
569        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
570        if data.len() < 5 {
571            assert_eq!(data.len(), 5);
572            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
573        }
574        let ptr = data.as_ptr() as *const [u8; 5];
575        // Safety: We checked length before
576        Ok(Self::from_bytes(unsafe { &*ptr }))
577    }
578
579    /// Create reference from byte array
580    pub fn from_bytes_slice_mut(data: &mut [u8]) -> Result<&mut Self, flatdata::ResourceStorageError> {
581        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
582        if data.len() < 5 {
583            assert_eq!(data.len(), 5);
584            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
585        }
586        let ptr = data.as_ptr() as *mut [u8; 5];
587        // Safety: We checked length before
588        Ok(Self::from_bytes_mut(unsafe { &mut *ptr }))
589    }
590
591    pub fn as_bytes(&self) -> &[u8; 5] {
592        &self.data
593    }
594}
595
596impl Default for NodeIndex {
597    fn default( ) -> Self {
598        Self::new( )
599    }
600}
601
602unsafe impl flatdata::NoOverlap for NodeIndex {}
603
604impl NodeIndex {
605    /// Index in the `nodes` vector.
606    #[inline]
607    pub fn value(&self) -> Option<u64> {
608        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
609        let x = unsafe { std::mem::transmute::<u64, u64>(value) };
610        Some(x).filter(|&x| x != super::osm::INVALID_IDX)
611    }
612
613}
614
615impl std::fmt::Debug for NodeIndex {
616    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
617        f.debug_struct("NodeIndex")
618            .field("value", &self.value())
619            .finish()
620    }
621}
622
623impl std::cmp::PartialEq for NodeIndex {
624    #[inline]
625    fn eq(&self, other: &Self) -> bool {
626        self.value() == other.value()     }
627}
628
629impl NodeIndex {
630    /// Index in the `nodes` vector.
631    #[inline]
632    #[allow(missing_docs)]
633    pub fn set_value(&mut self, value: Option<u64>) {
634let value = value.unwrap_or(super::osm::INVALID_IDX);        flatdata_write_bytes!(u64; value, self.data, 0, 40)
635    }
636
637
638    /// Copies the data from `other` into this struct.
639    #[inline]
640    pub fn fill_from(&mut self, other: &NodeIndex) {
641        self.set_value(other.value());
642    }
643}
644/// A way is an ordered list of nodes.
645///
646/// See <https://wiki.openstreetmap.org/wiki/Way>.
647#[repr(transparent)]
648pub struct Way {
649    data: [u8; 10],
650}
651
652impl Way {
653    /// Unsafe since the struct might not be self-contained
654    pub unsafe fn new_unchecked( ) -> Self {
655        Self{data : [0; 10]}
656    }
657}
658
659impl flatdata::Struct for Way {
660    unsafe fn create_unchecked( ) -> Self {
661        Self{data : [0; 10]}
662    }
663
664    const SIZE_IN_BYTES: usize = 10;
665    const IS_OVERLAPPING_WITH_NEXT : bool = true;
666}
667
668impl flatdata::Overlap for Way {}
669
670impl Way {
671    /// First element of the range [`tags`].
672    ///
673    /// [`tags`]: #method.tags
674    #[inline]
675    pub fn tag_first_idx(&self) -> u64 {
676        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
677        unsafe { std::mem::transmute::<u64, u64>(value) }
678    }
679
680    /// Range of tags attached to this node.
681///
682/// The values of the range are indexes in the `tags_index` vector.
683    #[inline]
684    pub fn tags(&self) -> std::ops::Range<u64> {
685        let start = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
686        let end = flatdata_read_bytes!(u64, self.data.as_ptr(), 0 + 10 * 8, 40);
687        start..end
688    }
689
690    /// First element of the range [`refs`].
691    ///
692    /// [`refs`]: #method.refs
693    #[inline]
694    pub fn ref_first_idx(&self) -> u64 {
695        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 40, 40);
696        unsafe { std::mem::transmute::<u64, u64>(value) }
697    }
698
699    /// Range of nodes this way consists of.
700///
701/// The values of the range are indexes in the `nodes_index` vector.
702    #[inline]
703    pub fn refs(&self) -> std::ops::Range<u64> {
704        let start = flatdata_read_bytes!(u64, self.data.as_ptr(), 40, 40);
705        let end = flatdata_read_bytes!(u64, self.data.as_ptr(), 40 + 10 * 8, 40);
706        start..end
707    }
708
709}
710
711impl std::fmt::Debug for Way {
712    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
713        f.debug_struct("Way")
714            .field("tag_first_idx", &self.tag_first_idx())
715            .field("ref_first_idx", &self.ref_first_idx())
716            .finish()
717    }
718}
719
720impl std::cmp::PartialEq for Way {
721    #[inline]
722    fn eq(&self, other: &Self) -> bool {
723        self.tag_first_idx() == other.tag_first_idx() &&        self.ref_first_idx() == other.ref_first_idx()     }
724}
725
726impl Way {
727    /// First element of the range [`tags`].
728    ///
729    /// [`tags`]: struct.WayRef.html#method.tags
730    #[inline]
731    #[allow(missing_docs)]
732    pub fn set_tag_first_idx(&mut self, value: u64) {
733        flatdata_write_bytes!(u64; value, self.data, 0, 40)
734    }
735
736    /// First element of the range [`refs`].
737    ///
738    /// [`refs`]: struct.WayRef.html#method.refs
739    #[inline]
740    #[allow(missing_docs)]
741    pub fn set_ref_first_idx(&mut self, value: u64) {
742        flatdata_write_bytes!(u64; value, self.data, 40, 40)
743    }
744
745
746    /// Copies the data from `other` into this struct.
747    #[inline]
748    pub fn fill_from(&mut self, other: &Way) {
749        self.set_tag_first_idx(other.tag_first_idx());
750        self.set_ref_first_idx(other.ref_first_idx());
751    }
752}
753/// Index of a tag.
754#[repr(transparent)]
755#[derive(Clone)]
756pub struct TagIndex {
757    data: [u8; 5],
758}
759
760impl TagIndex {
761    /// Unsafe since the struct might not be self-contained
762    pub unsafe fn new_unchecked( ) -> Self {
763        Self{data : [0; 5]}
764    }
765}
766
767impl flatdata::Struct for TagIndex {
768    unsafe fn create_unchecked( ) -> Self {
769        Self{data : [0; 5]}
770    }
771
772    const SIZE_IN_BYTES: usize = 5;
773    const IS_OVERLAPPING_WITH_NEXT : bool = false;
774}
775
776impl TagIndex {
777    pub fn new( ) -> Self {
778        Self{data : [0; 5]}
779    }
780
781    /// Create reference from byte array of matching size
782    pub fn from_bytes(data: &[u8; 5]) -> &Self {
783        // Safety: This is safe since TagIndex is repr(transparent)
784        unsafe{ std::mem::transmute( data ) }
785    }
786
787    /// Create reference from byte array of matching size
788    pub fn from_bytes_mut(data: &mut [u8; 5]) -> &mut Self {
789        // Safety: This is safe since TagIndex is repr(transparent)
790        unsafe{ std::mem::transmute( data ) }
791    }
792
793    /// Create reference from byte array
794    pub fn from_bytes_slice(data: &[u8]) -> Result<&Self, flatdata::ResourceStorageError> {
795        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
796        if data.len() < 5 {
797            assert_eq!(data.len(), 5);
798            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
799        }
800        let ptr = data.as_ptr() as *const [u8; 5];
801        // Safety: We checked length before
802        Ok(Self::from_bytes(unsafe { &*ptr }))
803    }
804
805    /// Create reference from byte array
806    pub fn from_bytes_slice_mut(data: &mut [u8]) -> Result<&mut Self, flatdata::ResourceStorageError> {
807        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
808        if data.len() < 5 {
809            assert_eq!(data.len(), 5);
810            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
811        }
812        let ptr = data.as_ptr() as *mut [u8; 5];
813        // Safety: We checked length before
814        Ok(Self::from_bytes_mut(unsafe { &mut *ptr }))
815    }
816
817    pub fn as_bytes(&self) -> &[u8; 5] {
818        &self.data
819    }
820}
821
822impl Default for TagIndex {
823    fn default( ) -> Self {
824        Self::new( )
825    }
826}
827
828unsafe impl flatdata::NoOverlap for TagIndex {}
829
830impl TagIndex {
831    /// Index in the `tags` vector.
832    #[inline]
833    pub fn value(&self) -> u64 {
834        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
835        unsafe { std::mem::transmute::<u64, u64>(value) }
836    }
837
838}
839
840impl std::fmt::Debug for TagIndex {
841    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
842        f.debug_struct("TagIndex")
843            .field("value", &self.value())
844            .finish()
845    }
846}
847
848impl std::cmp::PartialEq for TagIndex {
849    #[inline]
850    fn eq(&self, other: &Self) -> bool {
851        self.value() == other.value()     }
852}
853
854impl TagIndex {
855    /// Index in the `tags` vector.
856    #[inline]
857    #[allow(missing_docs)]
858    pub fn set_value(&mut self, value: u64) {
859        flatdata_write_bytes!(u64; value, self.data, 0, 40)
860    }
861
862
863    /// Copies the data from `other` into this struct.
864    #[inline]
865    pub fn fill_from(&mut self, other: &TagIndex) {
866        self.set_value(other.value());
867    }
868}
869/// Node member of a relation.
870#[repr(transparent)]
871#[derive(Clone)]
872pub struct NodeMember {
873    data: [u8; 10],
874}
875
876impl NodeMember {
877    /// Unsafe since the struct might not be self-contained
878    pub unsafe fn new_unchecked( ) -> Self {
879        Self{data : [0; 10]}
880    }
881}
882
883impl flatdata::Struct for NodeMember {
884    unsafe fn create_unchecked( ) -> Self {
885        Self{data : [0; 10]}
886    }
887
888    const SIZE_IN_BYTES: usize = 10;
889    const IS_OVERLAPPING_WITH_NEXT : bool = false;
890}
891
892impl NodeMember {
893    pub fn new( ) -> Self {
894        Self{data : [0; 10]}
895    }
896
897    /// Create reference from byte array of matching size
898    pub fn from_bytes(data: &[u8; 10]) -> &Self {
899        // Safety: This is safe since NodeMember is repr(transparent)
900        unsafe{ std::mem::transmute( data ) }
901    }
902
903    /// Create reference from byte array of matching size
904    pub fn from_bytes_mut(data: &mut [u8; 10]) -> &mut Self {
905        // Safety: This is safe since NodeMember is repr(transparent)
906        unsafe{ std::mem::transmute( data ) }
907    }
908
909    /// Create reference from byte array
910    pub fn from_bytes_slice(data: &[u8]) -> Result<&Self, flatdata::ResourceStorageError> {
911        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
912        if data.len() < 10 {
913            assert_eq!(data.len(), 10);
914            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
915        }
916        let ptr = data.as_ptr() as *const [u8; 10];
917        // Safety: We checked length before
918        Ok(Self::from_bytes(unsafe { &*ptr }))
919    }
920
921    /// Create reference from byte array
922    pub fn from_bytes_slice_mut(data: &mut [u8]) -> Result<&mut Self, flatdata::ResourceStorageError> {
923        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
924        if data.len() < 10 {
925            assert_eq!(data.len(), 10);
926            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
927        }
928        let ptr = data.as_ptr() as *mut [u8; 10];
929        // Safety: We checked length before
930        Ok(Self::from_bytes_mut(unsafe { &mut *ptr }))
931    }
932
933    pub fn as_bytes(&self) -> &[u8; 10] {
934        &self.data
935    }
936}
937
938impl Default for NodeMember {
939    fn default( ) -> Self {
940        Self::new( )
941    }
942}
943
944unsafe impl flatdata::NoOverlap for NodeMember {}
945
946impl NodeMember {
947    /// Index of the node in the `nodes` vector.
948    #[inline]
949    pub fn node_idx(&self) -> Option<u64> {
950        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
951        let x = unsafe { std::mem::transmute::<u64, u64>(value) };
952        Some(x).filter(|&x| x != super::osm::INVALID_IDX)
953    }
954
955    /// Optional textual field describing the function of the node in the relation.
956///
957/// Index in `stringtable`.
958    #[inline]
959    pub fn role_idx(&self) -> u64 {
960        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 40, 40);
961        unsafe { std::mem::transmute::<u64, u64>(value) }
962    }
963
964}
965
966impl std::fmt::Debug for NodeMember {
967    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
968        f.debug_struct("NodeMember")
969            .field("node_idx", &self.node_idx())
970            .field("role_idx", &self.role_idx())
971            .finish()
972    }
973}
974
975impl std::cmp::PartialEq for NodeMember {
976    #[inline]
977    fn eq(&self, other: &Self) -> bool {
978        self.node_idx() == other.node_idx() &&        self.role_idx() == other.role_idx()     }
979}
980
981impl NodeMember {
982    /// Index of the node in the `nodes` vector.
983    #[inline]
984    #[allow(missing_docs)]
985    pub fn set_node_idx(&mut self, value: Option<u64>) {
986let value = value.unwrap_or(super::osm::INVALID_IDX);        flatdata_write_bytes!(u64; value, self.data, 0, 40)
987    }
988
989    /// Optional textual field describing the function of the node in the relation.
990///
991/// Index in `stringtable`.
992    #[inline]
993    #[allow(missing_docs)]
994    pub fn set_role_idx(&mut self, value: u64) {
995        flatdata_write_bytes!(u64; value, self.data, 40, 40)
996    }
997
998
999    /// Copies the data from `other` into this struct.
1000    #[inline]
1001    pub fn fill_from(&mut self, other: &NodeMember) {
1002        self.set_node_idx(other.node_idx());
1003        self.set_role_idx(other.role_idx());
1004    }
1005}
1006/// Way member of a relation.
1007#[repr(transparent)]
1008#[derive(Clone)]
1009pub struct WayMember {
1010    data: [u8; 10],
1011}
1012
1013impl WayMember {
1014    /// Unsafe since the struct might not be self-contained
1015    pub unsafe fn new_unchecked( ) -> Self {
1016        Self{data : [0; 10]}
1017    }
1018}
1019
1020impl flatdata::Struct for WayMember {
1021    unsafe fn create_unchecked( ) -> Self {
1022        Self{data : [0; 10]}
1023    }
1024
1025    const SIZE_IN_BYTES: usize = 10;
1026    const IS_OVERLAPPING_WITH_NEXT : bool = false;
1027}
1028
1029impl WayMember {
1030    pub fn new( ) -> Self {
1031        Self{data : [0; 10]}
1032    }
1033
1034    /// Create reference from byte array of matching size
1035    pub fn from_bytes(data: &[u8; 10]) -> &Self {
1036        // Safety: This is safe since WayMember is repr(transparent)
1037        unsafe{ std::mem::transmute( data ) }
1038    }
1039
1040    /// Create reference from byte array of matching size
1041    pub fn from_bytes_mut(data: &mut [u8; 10]) -> &mut Self {
1042        // Safety: This is safe since WayMember is repr(transparent)
1043        unsafe{ std::mem::transmute( data ) }
1044    }
1045
1046    /// Create reference from byte array
1047    pub fn from_bytes_slice(data: &[u8]) -> Result<&Self, flatdata::ResourceStorageError> {
1048        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
1049        if data.len() < 10 {
1050            assert_eq!(data.len(), 10);
1051            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
1052        }
1053        let ptr = data.as_ptr() as *const [u8; 10];
1054        // Safety: We checked length before
1055        Ok(Self::from_bytes(unsafe { &*ptr }))
1056    }
1057
1058    /// Create reference from byte array
1059    pub fn from_bytes_slice_mut(data: &mut [u8]) -> Result<&mut Self, flatdata::ResourceStorageError> {
1060        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
1061        if data.len() < 10 {
1062            assert_eq!(data.len(), 10);
1063            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
1064        }
1065        let ptr = data.as_ptr() as *mut [u8; 10];
1066        // Safety: We checked length before
1067        Ok(Self::from_bytes_mut(unsafe { &mut *ptr }))
1068    }
1069
1070    pub fn as_bytes(&self) -> &[u8; 10] {
1071        &self.data
1072    }
1073}
1074
1075impl Default for WayMember {
1076    fn default( ) -> Self {
1077        Self::new( )
1078    }
1079}
1080
1081unsafe impl flatdata::NoOverlap for WayMember {}
1082
1083impl WayMember {
1084    /// Index of the way in the `ways` vector.
1085    #[inline]
1086    pub fn way_idx(&self) -> Option<u64> {
1087        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
1088        let x = unsafe { std::mem::transmute::<u64, u64>(value) };
1089        Some(x).filter(|&x| x != super::osm::INVALID_IDX)
1090    }
1091
1092    /// Optional textual field describing the function of the way in the relation.
1093///
1094/// Index in `stringtable`.
1095    #[inline]
1096    pub fn role_idx(&self) -> u64 {
1097        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 40, 40);
1098        unsafe { std::mem::transmute::<u64, u64>(value) }
1099    }
1100
1101}
1102
1103impl std::fmt::Debug for WayMember {
1104    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1105        f.debug_struct("WayMember")
1106            .field("way_idx", &self.way_idx())
1107            .field("role_idx", &self.role_idx())
1108            .finish()
1109    }
1110}
1111
1112impl std::cmp::PartialEq for WayMember {
1113    #[inline]
1114    fn eq(&self, other: &Self) -> bool {
1115        self.way_idx() == other.way_idx() &&        self.role_idx() == other.role_idx()     }
1116}
1117
1118impl WayMember {
1119    /// Index of the way in the `ways` vector.
1120    #[inline]
1121    #[allow(missing_docs)]
1122    pub fn set_way_idx(&mut self, value: Option<u64>) {
1123let value = value.unwrap_or(super::osm::INVALID_IDX);        flatdata_write_bytes!(u64; value, self.data, 0, 40)
1124    }
1125
1126    /// Optional textual field describing the function of the way in the relation.
1127///
1128/// Index in `stringtable`.
1129    #[inline]
1130    #[allow(missing_docs)]
1131    pub fn set_role_idx(&mut self, value: u64) {
1132        flatdata_write_bytes!(u64; value, self.data, 40, 40)
1133    }
1134
1135
1136    /// Copies the data from `other` into this struct.
1137    #[inline]
1138    pub fn fill_from(&mut self, other: &WayMember) {
1139        self.set_way_idx(other.way_idx());
1140        self.set_role_idx(other.role_idx());
1141    }
1142}
1143/// Relation member of a relation.
1144#[repr(transparent)]
1145#[derive(Clone)]
1146pub struct RelationMember {
1147    data: [u8; 10],
1148}
1149
1150impl RelationMember {
1151    /// Unsafe since the struct might not be self-contained
1152    pub unsafe fn new_unchecked( ) -> Self {
1153        Self{data : [0; 10]}
1154    }
1155}
1156
1157impl flatdata::Struct for RelationMember {
1158    unsafe fn create_unchecked( ) -> Self {
1159        Self{data : [0; 10]}
1160    }
1161
1162    const SIZE_IN_BYTES: usize = 10;
1163    const IS_OVERLAPPING_WITH_NEXT : bool = false;
1164}
1165
1166impl RelationMember {
1167    pub fn new( ) -> Self {
1168        Self{data : [0; 10]}
1169    }
1170
1171    /// Create reference from byte array of matching size
1172    pub fn from_bytes(data: &[u8; 10]) -> &Self {
1173        // Safety: This is safe since RelationMember is repr(transparent)
1174        unsafe{ std::mem::transmute( data ) }
1175    }
1176
1177    /// Create reference from byte array of matching size
1178    pub fn from_bytes_mut(data: &mut [u8; 10]) -> &mut Self {
1179        // Safety: This is safe since RelationMember is repr(transparent)
1180        unsafe{ std::mem::transmute( data ) }
1181    }
1182
1183    /// Create reference from byte array
1184    pub fn from_bytes_slice(data: &[u8]) -> Result<&Self, flatdata::ResourceStorageError> {
1185        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
1186        if data.len() < 10 {
1187            assert_eq!(data.len(), 10);
1188            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
1189        }
1190        let ptr = data.as_ptr() as *const [u8; 10];
1191        // Safety: We checked length before
1192        Ok(Self::from_bytes(unsafe { &*ptr }))
1193    }
1194
1195    /// Create reference from byte array
1196    pub fn from_bytes_slice_mut(data: &mut [u8]) -> Result<&mut Self, flatdata::ResourceStorageError> {
1197        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
1198        if data.len() < 10 {
1199            assert_eq!(data.len(), 10);
1200            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
1201        }
1202        let ptr = data.as_ptr() as *mut [u8; 10];
1203        // Safety: We checked length before
1204        Ok(Self::from_bytes_mut(unsafe { &mut *ptr }))
1205    }
1206
1207    pub fn as_bytes(&self) -> &[u8; 10] {
1208        &self.data
1209    }
1210}
1211
1212impl Default for RelationMember {
1213    fn default( ) -> Self {
1214        Self::new( )
1215    }
1216}
1217
1218unsafe impl flatdata::NoOverlap for RelationMember {}
1219
1220impl RelationMember {
1221    /// Index of the relation in the `relations` vector.
1222    #[inline]
1223    pub fn relation_idx(&self) -> Option<u64> {
1224        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
1225        let x = unsafe { std::mem::transmute::<u64, u64>(value) };
1226        Some(x).filter(|&x| x != super::osm::INVALID_IDX)
1227    }
1228
1229    /// Optional textual field describing the function of the relation in the parent relation.
1230///
1231/// Index in `stringtable`.
1232    #[inline]
1233    pub fn role_idx(&self) -> u64 {
1234        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 40, 40);
1235        unsafe { std::mem::transmute::<u64, u64>(value) }
1236    }
1237
1238}
1239
1240impl std::fmt::Debug for RelationMember {
1241    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1242        f.debug_struct("RelationMember")
1243            .field("relation_idx", &self.relation_idx())
1244            .field("role_idx", &self.role_idx())
1245            .finish()
1246    }
1247}
1248
1249impl std::cmp::PartialEq for RelationMember {
1250    #[inline]
1251    fn eq(&self, other: &Self) -> bool {
1252        self.relation_idx() == other.relation_idx() &&        self.role_idx() == other.role_idx()     }
1253}
1254
1255impl RelationMember {
1256    /// Index of the relation in the `relations` vector.
1257    #[inline]
1258    #[allow(missing_docs)]
1259    pub fn set_relation_idx(&mut self, value: Option<u64>) {
1260let value = value.unwrap_or(super::osm::INVALID_IDX);        flatdata_write_bytes!(u64; value, self.data, 0, 40)
1261    }
1262
1263    /// Optional textual field describing the function of the relation in the parent relation.
1264///
1265/// Index in `stringtable`.
1266    #[inline]
1267    #[allow(missing_docs)]
1268    pub fn set_role_idx(&mut self, value: u64) {
1269        flatdata_write_bytes!(u64; value, self.data, 40, 40)
1270    }
1271
1272
1273    /// Copies the data from `other` into this struct.
1274    #[inline]
1275    pub fn fill_from(&mut self, other: &RelationMember) {
1276        self.set_relation_idx(other.relation_idx());
1277        self.set_role_idx(other.role_idx());
1278    }
1279}
1280/// A relation is an ordered list of one or more nodes, ways and/or relations as members.
1281///
1282/// See <https://wiki.openstreetmap.org/wiki/Relation>.
1283#[repr(transparent)]
1284pub struct Relation {
1285    data: [u8; 5],
1286}
1287
1288impl Relation {
1289    /// Unsafe since the struct might not be self-contained
1290    pub unsafe fn new_unchecked( ) -> Self {
1291        Self{data : [0; 5]}
1292    }
1293}
1294
1295impl flatdata::Struct for Relation {
1296    unsafe fn create_unchecked( ) -> Self {
1297        Self{data : [0; 5]}
1298    }
1299
1300    const SIZE_IN_BYTES: usize = 5;
1301    const IS_OVERLAPPING_WITH_NEXT : bool = true;
1302}
1303
1304impl flatdata::Overlap for Relation {}
1305
1306impl Relation {
1307    /// First element of the range [`tags`].
1308    ///
1309    /// [`tags`]: #method.tags
1310    #[inline]
1311    pub fn tag_first_idx(&self) -> u64 {
1312        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
1313        unsafe { std::mem::transmute::<u64, u64>(value) }
1314    }
1315
1316    /// Range of tags attached to this relation.
1317///
1318/// The values of the range are indexes in the `tags` vector.
1319    #[inline]
1320    pub fn tags(&self) -> std::ops::Range<u64> {
1321        let start = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
1322        let end = flatdata_read_bytes!(u64, self.data.as_ptr(), 0 + 5 * 8, 40);
1323        start..end
1324    }
1325
1326}
1327
1328impl std::fmt::Debug for Relation {
1329    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1330        f.debug_struct("Relation")
1331            .field("tag_first_idx", &self.tag_first_idx())
1332            .finish()
1333    }
1334}
1335
1336impl std::cmp::PartialEq for Relation {
1337    #[inline]
1338    fn eq(&self, other: &Self) -> bool {
1339        self.tag_first_idx() == other.tag_first_idx()     }
1340}
1341
1342impl Relation {
1343    /// First element of the range [`tags`].
1344    ///
1345    /// [`tags`]: struct.RelationRef.html#method.tags
1346    #[inline]
1347    #[allow(missing_docs)]
1348    pub fn set_tag_first_idx(&mut self, value: u64) {
1349        flatdata_write_bytes!(u64; value, self.data, 0, 40)
1350    }
1351
1352
1353    /// Copies the data from `other` into this struct.
1354    #[inline]
1355    pub fn fill_from(&mut self, other: &Relation) {
1356        self.set_tag_first_idx(other.tag_first_idx());
1357    }
1358}
1359#[repr(transparent)]
1360#[derive(Clone)]
1361pub struct Id {
1362    data: [u8; 5],
1363}
1364
1365impl Id {
1366    /// Unsafe since the struct might not be self-contained
1367    pub unsafe fn new_unchecked( ) -> Self {
1368        Self{data : [0; 5]}
1369    }
1370}
1371
1372impl flatdata::Struct for Id {
1373    unsafe fn create_unchecked( ) -> Self {
1374        Self{data : [0; 5]}
1375    }
1376
1377    const SIZE_IN_BYTES: usize = 5;
1378    const IS_OVERLAPPING_WITH_NEXT : bool = false;
1379}
1380
1381impl Id {
1382    pub fn new( ) -> Self {
1383        Self{data : [0; 5]}
1384    }
1385
1386    /// Create reference from byte array of matching size
1387    pub fn from_bytes(data: &[u8; 5]) -> &Self {
1388        // Safety: This is safe since Id is repr(transparent)
1389        unsafe{ std::mem::transmute( data ) }
1390    }
1391
1392    /// Create reference from byte array of matching size
1393    pub fn from_bytes_mut(data: &mut [u8; 5]) -> &mut Self {
1394        // Safety: This is safe since Id is repr(transparent)
1395        unsafe{ std::mem::transmute( data ) }
1396    }
1397
1398    /// Create reference from byte array
1399    pub fn from_bytes_slice(data: &[u8]) -> Result<&Self, flatdata::ResourceStorageError> {
1400        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
1401        if data.len() < 5 {
1402            assert_eq!(data.len(), 5);
1403            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
1404        }
1405        let ptr = data.as_ptr() as *const [u8; 5];
1406        // Safety: We checked length before
1407        Ok(Self::from_bytes(unsafe { &*ptr }))
1408    }
1409
1410    /// Create reference from byte array
1411    pub fn from_bytes_slice_mut(data: &mut [u8]) -> Result<&mut Self, flatdata::ResourceStorageError> {
1412        // We cannot rely on TryFrom here, since it does not yet support > 33 bytes
1413        if data.len() < 5 {
1414            assert_eq!(data.len(), 5);
1415            return Err(flatdata::ResourceStorageError::UnexpectedDataSize);
1416        }
1417        let ptr = data.as_ptr() as *mut [u8; 5];
1418        // Safety: We checked length before
1419        Ok(Self::from_bytes_mut(unsafe { &mut *ptr }))
1420    }
1421
1422    pub fn as_bytes(&self) -> &[u8; 5] {
1423        &self.data
1424    }
1425}
1426
1427impl Default for Id {
1428    fn default( ) -> Self {
1429        Self::new( )
1430    }
1431}
1432
1433unsafe impl flatdata::NoOverlap for Id {}
1434
1435impl Id {
1436    #[inline]
1437    pub fn value(&self) -> u64 {
1438        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
1439        unsafe { std::mem::transmute::<u64, u64>(value) }
1440    }
1441
1442}
1443
1444impl std::fmt::Debug for Id {
1445    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1446        f.debug_struct("Id")
1447            .field("value", &self.value())
1448            .finish()
1449    }
1450}
1451
1452impl std::cmp::PartialEq for Id {
1453    #[inline]
1454    fn eq(&self, other: &Self) -> bool {
1455        self.value() == other.value()     }
1456}
1457
1458impl Id {
1459    #[inline]
1460    #[allow(missing_docs)]
1461    pub fn set_value(&mut self, value: u64) {
1462        flatdata_write_bytes!(u64; value, self.data, 0, 40)
1463    }
1464
1465
1466    /// Copies the data from `other` into this struct.
1467    #[inline]
1468    pub fn fill_from(&mut self, other: &Id) {
1469        self.set_value(other.value());
1470    }
1471}
1472
1473
1474
1475/// An optional sub-archive storing the original OSM ids of nodes, ways, and relations
1476#[derive(Clone)]
1477pub struct Ids {
1478    _storage: flatdata::StorageHandle,
1479    nodes : &'static [super::osm::Id],
1480    ways : &'static [super::osm::Id],
1481    relations : &'static [super::osm::Id],
1482}
1483
1484impl Ids {
1485    fn signature_name(archive_name: &str) -> String {
1486        format!("{}.archive", archive_name)
1487    }
1488
1489    /// List of OSM ids of all nodes in the parent archive
1490/// nodes[i] has its id stored in ids.nodes[i]
1491    #[inline]
1492    pub fn nodes(&self) -> &[super::osm::Id] {
1493        self.nodes
1494    }
1495
1496    /// List of OSM ids of all ways in the parent archive
1497/// ways[i] has its id stored in ids.ways[i]
1498    #[inline]
1499    pub fn ways(&self) -> &[super::osm::Id] {
1500        self.ways
1501    }
1502
1503    /// List of OSM ids of all relations in the parent archive
1504/// relations[i] has its id stored in ids.relations[i]
1505    #[inline]
1506    pub fn relations(&self) -> &[super::osm::Id] {
1507        self.relations
1508    }
1509
1510}
1511
1512impl ::std::fmt::Debug for Ids {
1513    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
1514        f.debug_struct("Ids")
1515            .field("nodes", &self.nodes())
1516            .field("ways", &self.ways())
1517            .field("relations", &self.relations())
1518            .finish()
1519    }
1520}
1521
1522impl Ids {
1523    pub fn open(storage: flatdata::StorageHandle)
1524        -> ::std::result::Result<Self, flatdata::ResourceStorageError>
1525    {
1526        #[allow(unused_imports)]
1527        use flatdata::SliceExt;
1528        #[allow(unused_variables)]
1529        use flatdata::ResourceStorageError as Error;
1530        // extend lifetime since Rust cannot know that we reference a cache here
1531        #[allow(unused_variables)]
1532        let extend = |x : Result<&[u8], Error>| -> Result<&'static [u8], Error> {x.map(|x| unsafe{std::mem::transmute(x)})};
1533
1534        storage.read(&Self::signature_name("Ids"), schema::ids::IDS)?;
1535
1536        let nodes = {
1537            use flatdata::check_resource as check;
1538            let max_size = None;
1539            let resource = extend(storage.read("nodes", schema::ids::resources::NODES));
1540            check("nodes", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::Id]>::from_bytes(x)))?
1541        };
1542        let ways = {
1543            use flatdata::check_resource as check;
1544            let max_size = None;
1545            let resource = extend(storage.read("ways", schema::ids::resources::WAYS));
1546            check("ways", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::Id]>::from_bytes(x)))?
1547        };
1548        let relations = {
1549            use flatdata::check_resource as check;
1550            let max_size = None;
1551            let resource = extend(storage.read("relations", schema::ids::resources::RELATIONS));
1552            check("relations", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::Id]>::from_bytes(x)))?
1553        };
1554
1555        Ok(Self {
1556            _storage: storage,
1557            nodes,
1558            ways,
1559            relations,
1560        })
1561    }
1562}
1563
1564/// Builder for creating [`Ids`] archives.
1565///
1566///[`Ids`]: struct.Ids.html
1567#[derive(Clone, Debug)]
1568pub struct IdsBuilder {
1569    storage: flatdata::StorageHandle
1570}
1571
1572impl IdsBuilder {
1573    #[inline]
1574    /// Stores [`nodes`] in the archive.
1575    ///
1576    /// [`nodes`]: struct.Ids.html#method.nodes
1577    pub fn set_nodes(&self, vector: &[super::osm::Id]) -> ::std::io::Result<()> {
1578        use flatdata::SliceExt;
1579        self.storage.write("nodes", schema::ids::resources::NODES, vector.as_bytes())
1580    }
1581
1582    /// Opens [`nodes`] in the archive for buffered writing.
1583    ///
1584    /// Elements can be added to the vector until the [`ExternalVector::close`] method
1585    /// is called. To flush the data fully into the archive, this method must be called
1586    /// in the end.
1587    ///
1588    /// [`nodes`]: struct.Ids.html#method.nodes
1589    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
1590    #[inline]
1591    pub fn start_nodes(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::Id>> {
1592        flatdata::create_external_vector(&*self.storage, "nodes", schema::ids::resources::NODES)
1593    }
1594
1595    #[inline]
1596    /// Stores [`ways`] in the archive.
1597    ///
1598    /// [`ways`]: struct.Ids.html#method.ways
1599    pub fn set_ways(&self, vector: &[super::osm::Id]) -> ::std::io::Result<()> {
1600        use flatdata::SliceExt;
1601        self.storage.write("ways", schema::ids::resources::WAYS, vector.as_bytes())
1602    }
1603
1604    /// Opens [`ways`] in the archive for buffered writing.
1605    ///
1606    /// Elements can be added to the vector until the [`ExternalVector::close`] method
1607    /// is called. To flush the data fully into the archive, this method must be called
1608    /// in the end.
1609    ///
1610    /// [`ways`]: struct.Ids.html#method.ways
1611    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
1612    #[inline]
1613    pub fn start_ways(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::Id>> {
1614        flatdata::create_external_vector(&*self.storage, "ways", schema::ids::resources::WAYS)
1615    }
1616
1617    #[inline]
1618    /// Stores [`relations`] in the archive.
1619    ///
1620    /// [`relations`]: struct.Ids.html#method.relations
1621    pub fn set_relations(&self, vector: &[super::osm::Id]) -> ::std::io::Result<()> {
1622        use flatdata::SliceExt;
1623        self.storage.write("relations", schema::ids::resources::RELATIONS, vector.as_bytes())
1624    }
1625
1626    /// Opens [`relations`] in the archive for buffered writing.
1627    ///
1628    /// Elements can be added to the vector until the [`ExternalVector::close`] method
1629    /// is called. To flush the data fully into the archive, this method must be called
1630    /// in the end.
1631    ///
1632    /// [`relations`]: struct.Ids.html#method.relations
1633    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
1634    #[inline]
1635    pub fn start_relations(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::Id>> {
1636        flatdata::create_external_vector(&*self.storage, "relations", schema::ids::resources::RELATIONS)
1637    }
1638
1639}
1640
1641impl IdsBuilder {
1642    pub fn new(
1643        storage: flatdata::StorageHandle,
1644    ) -> Result<Self, flatdata::ResourceStorageError> {
1645        flatdata::create_archive("Ids", schema::ids::IDS, &storage)?;
1646        Ok(Self { storage })
1647    }
1648}
1649
1650
1651
1652/// Enum for read-only heterogeneous access to elements in a
1653/// bucket of the [`relation_members`] resource.
1654///
1655/// [`relation_members`]: struct.Archive{.osm.Osm}.html#method.relation_members
1656#[derive(Clone, PartialEq)]
1657pub enum RelationMembersRef<'a> {
1658    #[allow(missing_docs)]
1659    NodeMember(&'a super::osm::NodeMember),    #[allow(missing_docs)]
1660    WayMember(&'a super::osm::WayMember),    #[allow(missing_docs)]
1661    RelationMember(&'a super::osm::RelationMember),}
1662
1663impl<'a> ::std::fmt::Debug for RelationMembersRef<'a> {
1664    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
1665        match *self {
1666            RelationMembersRef::NodeMember(ref inner) => write!(f, "{:?}", inner),
1667            RelationMembersRef::WayMember(ref inner) => write!(f, "{:?}", inner),
1668            RelationMembersRef::RelationMember(ref inner) => write!(f, "{:?}", inner),
1669        }
1670    }
1671}
1672
1673impl<'a> flatdata::VariadicRef for RelationMembersRef<'a> {
1674    #[inline]
1675    fn size_in_bytes(&self) -> usize {
1676        match *self {
1677            RelationMembersRef::NodeMember(_) => <super::osm::NodeMember as flatdata::Struct>::SIZE_IN_BYTES,
1678            RelationMembersRef::WayMember(_) => <super::osm::WayMember as flatdata::Struct>::SIZE_IN_BYTES,
1679            RelationMembersRef::RelationMember(_) => <super::osm::RelationMember as flatdata::Struct>::SIZE_IN_BYTES,
1680        }
1681    }
1682}
1683
1684/// Builder of buckets in the [`relation_members`] resource.
1685///
1686/// Refers to a single bucket in the [`relation_members`] multivector and
1687/// provides methods for adding heterogeneous data to the bucket.
1688///
1689/// [`relation_members`]: struct.Archive{.osm.Osm}.html#method.relation_members
1690pub struct RelationMembersBuilder<'a> {
1691    data: &'a mut Vec<u8>
1692}
1693
1694impl<'a> RelationMembersBuilder<'a> {
1695    /// Adds data of the type [`NodeMember`] to the bucket.
1696    ///
1697    /// [`NodeMember`]: struct.NodeMember.html
1698    #[inline]
1699    pub fn add_node_member<'b>(&'b mut self) -> &'b mut super::osm::NodeMember {
1700        let old_len = self.data.len();
1701        let increment = 1 + <super::osm::NodeMember as flatdata::Struct>::SIZE_IN_BYTES;
1702        self.data.resize(old_len + increment, 0);
1703        self.data[old_len] = 0;
1704        let slice = &mut self.data[1 + old_len..];
1705        super::osm::NodeMember::from_bytes_slice_mut(slice).expect("Logic error: Cannot create super::osm::NodeMember from slice")
1706    }
1707    /// Adds data of the type [`WayMember`] to the bucket.
1708    ///
1709    /// [`WayMember`]: struct.WayMember.html
1710    #[inline]
1711    pub fn add_way_member<'b>(&'b mut self) -> &'b mut super::osm::WayMember {
1712        let old_len = self.data.len();
1713        let increment = 1 + <super::osm::WayMember as flatdata::Struct>::SIZE_IN_BYTES;
1714        self.data.resize(old_len + increment, 0);
1715        self.data[old_len] = 1;
1716        let slice = &mut self.data[1 + old_len..];
1717        super::osm::WayMember::from_bytes_slice_mut(slice).expect("Logic error: Cannot create super::osm::WayMember from slice")
1718    }
1719    /// Adds data of the type [`RelationMember`] to the bucket.
1720    ///
1721    /// [`RelationMember`]: struct.RelationMember.html
1722    #[inline]
1723    pub fn add_relation_member<'b>(&'b mut self) -> &'b mut super::osm::RelationMember {
1724        let old_len = self.data.len();
1725        let increment = 1 + <super::osm::RelationMember as flatdata::Struct>::SIZE_IN_BYTES;
1726        self.data.resize(old_len + increment, 0);
1727        self.data[old_len] = 2;
1728        let slice = &mut self.data[1 + old_len..];
1729        super::osm::RelationMember::from_bytes_slice_mut(slice).expect("Logic error: Cannot create super::osm::RelationMember from slice")
1730    }
1731}
1732
1733/// Variadic struct attached to the [`relation_members`] archive resource.
1734///
1735/// It unifies the following data types:
1736//
1737/// * [`NodeMember`]
1738/// * [`WayMember`]
1739/// * [`RelationMember`]
1740///
1741/// ## Access pattern
1742///
1743/// This structure is used as a template parameter in [`relation_members`] multivector/
1744/// multiarray view. It does not contain any data, instead it references
1745///
1746/// * [`RelationMembersRef`] for the read-only heterogeneous access, and
1747/// * [`RelationMembersBuilder`] for the mutable builder pattern access.
1748///
1749/// [`relation_members`]: struct.Archive{.osm.Osm}.html#method.relation_members
1750/// [`RelationMembersRef`]: enum.RelationMembersRef.html
1751/// [`RelationMembersBuilder`]: struct.RelationMembersBuilder.html
1752/// [`NodeMember`]: struct.NodeMember.html
1753/// [`WayMember`]: struct.WayMember.html
1754/// [`RelationMember`]: struct.RelationMember.html
1755#[derive(Clone)]
1756pub struct RelationMembers {}
1757
1758impl flatdata::VariadicIndex for RelationMembers {
1759    type Index = super::_builtin::multivector::IndexType40;
1760}
1761
1762impl<'a> flatdata::VariadicStruct<'a> for RelationMembers {
1763    type Item = RelationMembersRef<'a>;
1764
1765    #[inline]
1766    fn create(index: flatdata::TypeIndex, data: &'a [u8]) -> Self::Item
1767    {
1768        match index {
1769                0 => RelationMembersRef::NodeMember(super::osm::NodeMember::from_bytes_slice(&data).expect("Corrupted data")),
1770                1 => RelationMembersRef::WayMember(super::osm::WayMember::from_bytes_slice(&data).expect("Corrupted data")),
1771                2 => RelationMembersRef::RelationMember(super::osm::RelationMember::from_bytes_slice(&data).expect("Corrupted data")),
1772            _ => panic!("invalid type index {} for variadic type RelationMembersRef", index),
1773        }
1774    }
1775
1776    type ItemMut = RelationMembersBuilder<'a>;
1777
1778    #[inline]
1779    fn create_mut(data: &'a mut Vec<u8>) -> Self::ItemMut
1780    {
1781        Self::ItemMut { data }
1782    }
1783}
1784
1785/// OSM data archive
1786///
1787/// Relations and relation members are indexed with the same index, i.e.
1788/// a relation at index `i` in the vector `relations` has the members
1789/// at index `i` in the multivector `relation_members`.
1790///
1791/// All 1:n relationships are modeled in-place by using an additional index. This is a
1792/// common pattern in flatdata. For example, a node might have multiple tags attached
1793/// to it. To model this, a node in `nodes` references the first tag attached to it
1794/// by storing an index in the `tags_index` vector. The next node in `nodes` again
1795/// references its first tag, which is the last tag (exclusive) of the previous node.
1796///
1797/// ```text
1798/// nodes:      [ ..., n_1, n_2, ... ]
1799///                     |    |
1800///                     |    +-------+
1801///                     v            v
1802/// tags_index: [ ..., t_11, t_12, ..., t_1n, t_21, ... t_2m, ... ]
1803/// ```
1804#[derive(Clone)]
1805pub struct Osm {
1806    _storage: flatdata::StorageHandle,
1807    header : &'static super::osm::Header,
1808    nodes : &'static [super::osm::Node],
1809    ways : &'static [super::osm::Way],
1810    relations : &'static [super::osm::Relation],
1811    relation_members : flatdata::MultiArrayView<'static, RelationMembers>,
1812    tags : &'static [super::osm::Tag],
1813    tags_index : &'static [super::osm::TagIndex],
1814    nodes_index : &'static [super::osm::NodeIndex],
1815    stringtable : flatdata::RawData<'static>,
1816    ids : Option<super::osm::Ids
1817>,
1818}
1819
1820impl Osm {
1821    fn signature_name(archive_name: &str) -> String {
1822        format!("{}.archive", archive_name)
1823    }
1824
1825    /// Header which contains the metadata attached to the archive.
1826    #[inline]
1827    pub fn header(&self) -> &super::osm::Header {
1828        self.header
1829    }
1830
1831    /// List of nodes.
1832///
1833/// A node references a range of tags in the `tags_index` vector.
1834    #[inline]
1835    pub fn nodes(&self) -> &[super::osm::Node] {
1836        self.nodes
1837    }
1838
1839    /// List of ways.
1840///
1841/// A way references
1842///
1843/// * a range of tags in the `tags_index` vector, and
1844/// * a range of nodes in the `nodes_index` vector.
1845    #[inline]
1846    pub fn ways(&self) -> &[super::osm::Way] {
1847        self.ways
1848    }
1849
1850    /// List of relations.
1851///
1852/// A relation references a range of tags in `tags_index` vectors.
1853/// Members are attached to a relation implicitly: members that belong to a
1854/// relation at index `i` are at index `i` in the `relation_members` multivector.
1855    #[inline]
1856    pub fn relations(&self) -> &[super::osm::Relation] {
1857        self.relations
1858    }
1859
1860    /// Members attached to relations.
1861///
1862/// An index in this multivector corresponds to an index in the `relations` vector.
1863///
1864/// A member has a variadic type: `NodeMember`, `WayMember` or `RelationMember`.
1865/// Each type references its role in the `stringtable` raw data. Additionally,
1866///
1867/// * a node member references a node in the `nodes` vector,
1868/// * a way member references a way in the `ways` vector,
1869/// * a relation member references a relation in the `relations` vector.
1870    #[inline]
1871    pub fn relation_members(&self) -> &flatdata::MultiArrayView<RelationMembers> {
1872        &self.relation_members
1873    }
1874
1875    /// List of tags.
1876///
1877/// A tag references its key and value in the `stringtable` raw data.
1878    #[inline]
1879    pub fn tags(&self) -> &[super::osm::Tag] {
1880        self.tags
1881    }
1882
1883    /// Auxiliary index of tags to model 1:n relationships between nodes, ways, relations
1884/// and tags.
1885    #[inline]
1886    pub fn tags_index(&self) -> &[super::osm::TagIndex] {
1887        self.tags_index
1888    }
1889
1890    /// Auxiliary index of nodes to model 1:n relationship between ways and nodes.
1891    #[inline]
1892    pub fn nodes_index(&self) -> &[super::osm::NodeIndex] {
1893        self.nodes_index
1894    }
1895
1896    /// List of strings separated by `\0`.
1897    #[inline]
1898    pub fn stringtable(&self) -> flatdata::RawData {
1899        self.stringtable
1900    }
1901
1902    #[inline]
1903    pub fn ids(&self) -> Option<&super::osm::Ids> {
1904        self.ids.as_ref()
1905    }
1906
1907}
1908
1909impl ::std::fmt::Debug for Osm {
1910    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
1911        f.debug_struct("Osm")
1912            .field("header", &self.header())
1913            .field("nodes", &self.nodes())
1914            .field("ways", &self.ways())
1915            .field("relations", &self.relations())
1916            .field("relation_members", &self.relation_members())
1917            .field("tags", &self.tags())
1918            .field("tags_index", &self.tags_index())
1919            .field("nodes_index", &self.nodes_index())
1920            .field("stringtable", &self.stringtable())
1921            .field("ids", &self.ids())
1922            .finish()
1923    }
1924}
1925
1926impl Osm {
1927    pub fn open(storage: flatdata::StorageHandle)
1928        -> ::std::result::Result<Self, flatdata::ResourceStorageError>
1929    {
1930        #[allow(unused_imports)]
1931        use flatdata::SliceExt;
1932        #[allow(unused_variables)]
1933        use flatdata::ResourceStorageError as Error;
1934        // extend lifetime since Rust cannot know that we reference a cache here
1935        #[allow(unused_variables)]
1936        let extend = |x : Result<&[u8], Error>| -> Result<&'static [u8], Error> {x.map(|x| unsafe{std::mem::transmute(x)})};
1937
1938        storage.read(&Self::signature_name("Osm"), schema::osm::OSM)?;
1939
1940        let header = {
1941            use flatdata::check_resource as check;
1942            let max_size = None;
1943            let resource = extend(storage.read("header", schema::osm::resources::HEADER));
1944            check("header", |_| 0, max_size, resource.and_then(|x| super::osm::Header::from_bytes_slice(x)))?
1945        };
1946        let nodes = {
1947            use flatdata::check_resource as check;
1948            let max_size = Some(1099511627776);
1949            let resource = extend(storage.read("nodes", schema::osm::resources::NODES));
1950            check("nodes", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::Node]>::from_bytes(x)))?
1951        };
1952        let ways = {
1953            use flatdata::check_resource as check;
1954            let max_size = Some(1099511627776);
1955            let resource = extend(storage.read("ways", schema::osm::resources::WAYS));
1956            check("ways", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::Way]>::from_bytes(x)))?
1957        };
1958        let relations = {
1959            use flatdata::check_resource as check;
1960            let max_size = Some(1099511627776);
1961            let resource = extend(storage.read("relations", schema::osm::resources::RELATIONS));
1962            check("relations", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::Relation]>::from_bytes(x)))?
1963        };
1964        let relation_members = {
1965            use flatdata::check_resource as check;
1966            let max_size = None;
1967            let index_schema = &format!("index({})", schema::osm::resources::RELATION_MEMBERS);
1968            let index = extend(storage.read("relation_members_index", &index_schema));
1969            let data = extend(storage.read("relation_members", schema::osm::resources::RELATION_MEMBERS));
1970            let result = match (index, data) {
1971                (Ok(index), Ok(data)) => {
1972                    Ok(flatdata::MultiArrayView::new(
1973                        <&[super::_builtin::multivector::IndexType40]>::from_bytes(index)?,
1974                        data
1975                    ))
1976                }
1977                // is resource completely missing?
1978                (Err(Error::Missing), Err(Error::Missing))  => Err(Error::Missing),
1979                // is resource partially missing / broken -> extract best error to propagate
1980                (Ok(_), Err(Error::Missing)) | (Err(Error::Missing), Ok(_)) => Err(Error::MissingData),
1981                (Err(Error::Missing), Err(x)) | (Err(x), Err(Error::Missing)) => {return Err(x);}
1982                (_, Err(x)) | (Err(x), _) => {return Err(x);}
1983            };
1984            check("relation_members", |r| r.len(), max_size, result)?
1985        };
1986        let tags = {
1987            use flatdata::check_resource as check;
1988            let max_size = Some(1099511627776);
1989            let resource = extend(storage.read("tags", schema::osm::resources::TAGS));
1990            check("tags", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::Tag]>::from_bytes(x)))?
1991        };
1992        let tags_index = {
1993            use flatdata::check_resource as check;
1994            let max_size = Some(1099511627776);
1995            let resource = extend(storage.read("tags_index", schema::osm::resources::TAGS_INDEX));
1996            check("tags_index", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::TagIndex]>::from_bytes(x)))?
1997        };
1998        let nodes_index = {
1999            use flatdata::check_resource as check;
2000            let max_size = Some(1099511627776);
2001            let resource = extend(storage.read("nodes_index", schema::osm::resources::NODES_INDEX));
2002            check("nodes_index", |r| r.len(), max_size, resource.and_then(|x| <&[super::osm::NodeIndex]>::from_bytes(x)))?
2003        };
2004        let stringtable = {
2005            use flatdata::check_resource as check;
2006            let max_size = Some(1099511627776);
2007            let resource = extend(storage.read("stringtable", schema::osm::resources::STRINGTABLE));
2008            check("stringtable", |r| r.len(), max_size, resource.map(|x| flatdata::RawData::new(x)))?
2009        };
2010        let ids = {
2011            use flatdata::check_optional_resource as check;
2012            let max_size = None;
2013            check("ids", |_| 0, max_size, super::osm::Ids::open(storage.subdir("ids")))?
2014        };
2015
2016        Ok(Self {
2017            _storage: storage,
2018            header,
2019            nodes,
2020            ways,
2021            relations,
2022            relation_members,
2023            tags,
2024            tags_index,
2025            nodes_index,
2026            stringtable,
2027            ids,
2028        })
2029    }
2030}
2031
2032/// Builder for creating [`Osm`] archives.
2033///
2034///[`Osm`]: struct.Osm.html
2035#[derive(Clone, Debug)]
2036pub struct OsmBuilder {
2037    storage: flatdata::StorageHandle
2038}
2039
2040impl OsmBuilder {
2041    #[inline]
2042    /// Stores [`header`] in the archive.
2043    ///
2044    /// [`header`]: struct.Osm.html#method.header
2045    /// Stores [`header`] in the archive.
2046    pub fn set_header(&self, resource: &super::osm::Header) -> ::std::io::Result<()> {
2047        let data = resource.as_bytes();
2048        self.storage.write("header", schema::osm::resources::HEADER, data)
2049    }
2050
2051    #[inline]
2052    /// Stores [`nodes`] in the archive.
2053    ///
2054    /// [`nodes`]: struct.Osm.html#method.nodes
2055    pub fn set_nodes(&self, vector: &[super::osm::Node]) -> ::std::io::Result<()> {
2056        use flatdata::SliceExt;
2057        self.storage.write("nodes", schema::osm::resources::NODES, vector.as_bytes())
2058    }
2059
2060    /// Opens [`nodes`] in the archive for buffered writing.
2061    ///
2062    /// Elements can be added to the vector until the [`ExternalVector::close`] method
2063    /// is called. To flush the data fully into the archive, this method must be called
2064    /// in the end.
2065    ///
2066    /// [`nodes`]: struct.Osm.html#method.nodes
2067    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
2068    #[inline]
2069    pub fn start_nodes(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::Node>> {
2070        flatdata::create_external_vector(&*self.storage, "nodes", schema::osm::resources::NODES)
2071    }
2072
2073    #[inline]
2074    /// Stores [`ways`] in the archive.
2075    ///
2076    /// [`ways`]: struct.Osm.html#method.ways
2077    pub fn set_ways(&self, vector: &[super::osm::Way]) -> ::std::io::Result<()> {
2078        use flatdata::SliceExt;
2079        self.storage.write("ways", schema::osm::resources::WAYS, vector.as_bytes())
2080    }
2081
2082    /// Opens [`ways`] in the archive for buffered writing.
2083    ///
2084    /// Elements can be added to the vector until the [`ExternalVector::close`] method
2085    /// is called. To flush the data fully into the archive, this method must be called
2086    /// in the end.
2087    ///
2088    /// [`ways`]: struct.Osm.html#method.ways
2089    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
2090    #[inline]
2091    pub fn start_ways(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::Way>> {
2092        flatdata::create_external_vector(&*self.storage, "ways", schema::osm::resources::WAYS)
2093    }
2094
2095    #[inline]
2096    /// Stores [`relations`] in the archive.
2097    ///
2098    /// [`relations`]: struct.Osm.html#method.relations
2099    pub fn set_relations(&self, vector: &[super::osm::Relation]) -> ::std::io::Result<()> {
2100        use flatdata::SliceExt;
2101        self.storage.write("relations", schema::osm::resources::RELATIONS, vector.as_bytes())
2102    }
2103
2104    /// Opens [`relations`] in the archive for buffered writing.
2105    ///
2106    /// Elements can be added to the vector until the [`ExternalVector::close`] method
2107    /// is called. To flush the data fully into the archive, this method must be called
2108    /// in the end.
2109    ///
2110    /// [`relations`]: struct.Osm.html#method.relations
2111    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
2112    #[inline]
2113    pub fn start_relations(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::Relation>> {
2114        flatdata::create_external_vector(&*self.storage, "relations", schema::osm::resources::RELATIONS)
2115    }
2116
2117    /// Opens [`relation_members`] in the archive for buffered writing.
2118    ///
2119    /// Elements can be added to the multivector until the [`MultiVector::close`] method
2120    /// is called. To flush the data fully into the archive, this method must be called
2121    /// in the end.
2122    ///
2123    /// [`relation_members`]: struct.Osm.html#method.relation_members
2124    /// [`MultiVector::close`]: flatdata/struct.MultiVector.html#method.close
2125    #[inline]
2126    pub fn start_relation_members(&self) -> ::std::io::Result<flatdata::MultiVector<RelationMembers>> {
2127        flatdata::create_multi_vector(&*self.storage, "relation_members", schema::osm::resources::RELATION_MEMBERS)
2128    }
2129
2130    #[inline]
2131    /// Stores [`tags`] in the archive.
2132    ///
2133    /// [`tags`]: struct.Osm.html#method.tags
2134    pub fn set_tags(&self, vector: &[super::osm::Tag]) -> ::std::io::Result<()> {
2135        use flatdata::SliceExt;
2136        self.storage.write("tags", schema::osm::resources::TAGS, vector.as_bytes())
2137    }
2138
2139    /// Opens [`tags`] in the archive for buffered writing.
2140    ///
2141    /// Elements can be added to the vector until the [`ExternalVector::close`] method
2142    /// is called. To flush the data fully into the archive, this method must be called
2143    /// in the end.
2144    ///
2145    /// [`tags`]: struct.Osm.html#method.tags
2146    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
2147    #[inline]
2148    pub fn start_tags(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::Tag>> {
2149        flatdata::create_external_vector(&*self.storage, "tags", schema::osm::resources::TAGS)
2150    }
2151
2152    #[inline]
2153    /// Stores [`tags_index`] in the archive.
2154    ///
2155    /// [`tags_index`]: struct.Osm.html#method.tags_index
2156    pub fn set_tags_index(&self, vector: &[super::osm::TagIndex]) -> ::std::io::Result<()> {
2157        use flatdata::SliceExt;
2158        self.storage.write("tags_index", schema::osm::resources::TAGS_INDEX, vector.as_bytes())
2159    }
2160
2161    /// Opens [`tags_index`] in the archive for buffered writing.
2162    ///
2163    /// Elements can be added to the vector until the [`ExternalVector::close`] method
2164    /// is called. To flush the data fully into the archive, this method must be called
2165    /// in the end.
2166    ///
2167    /// [`tags_index`]: struct.Osm.html#method.tags_index
2168    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
2169    #[inline]
2170    pub fn start_tags_index(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::TagIndex>> {
2171        flatdata::create_external_vector(&*self.storage, "tags_index", schema::osm::resources::TAGS_INDEX)
2172    }
2173
2174    #[inline]
2175    /// Stores [`nodes_index`] in the archive.
2176    ///
2177    /// [`nodes_index`]: struct.Osm.html#method.nodes_index
2178    pub fn set_nodes_index(&self, vector: &[super::osm::NodeIndex]) -> ::std::io::Result<()> {
2179        use flatdata::SliceExt;
2180        self.storage.write("nodes_index", schema::osm::resources::NODES_INDEX, vector.as_bytes())
2181    }
2182
2183    /// Opens [`nodes_index`] in the archive for buffered writing.
2184    ///
2185    /// Elements can be added to the vector until the [`ExternalVector::close`] method
2186    /// is called. To flush the data fully into the archive, this method must be called
2187    /// in the end.
2188    ///
2189    /// [`nodes_index`]: struct.Osm.html#method.nodes_index
2190    /// [`ExternalVector::close`]: flatdata/struct.ExternalVector.html#method.close
2191    #[inline]
2192    pub fn start_nodes_index(&self) -> ::std::io::Result<flatdata::ExternalVector<super::osm::NodeIndex>> {
2193        flatdata::create_external_vector(&*self.storage, "nodes_index", schema::osm::resources::NODES_INDEX)
2194    }
2195
2196    /// Stores [`stringtable`] in the archive.
2197    ///
2198    /// [`stringtable`]: struct.Osm.html#method.stringtable
2199    #[inline]
2200    pub fn set_stringtable(&self, data: &[u8]) -> ::std::io::Result<()> {
2201        self.storage.write("stringtable", schema::osm::resources::STRINGTABLE, data)
2202    }
2203
2204    /// Stores [`ids`] in the archive.
2205    ///
2206    /// [`ids`]: struct.Osm.html#method.ids
2207    #[inline]
2208    pub fn ids(&self) -> Result<super::osm::IdsBuilder, flatdata::ResourceStorageError> {
2209        let storage = self.storage.subdir("ids");
2210        super::osm::IdsBuilder::new(storage)
2211    }
2212
2213}
2214
2215impl OsmBuilder {
2216    pub fn new(
2217        storage: flatdata::StorageHandle,
2218    ) -> Result<Self, flatdata::ResourceStorageError> {
2219        flatdata::create_archive("Osm", schema::osm::OSM, &storage)?;
2220        Ok(Self { storage })
2221    }
2222}
2223
2224
2225#[doc(hidden)]
2226pub mod schema {
2227pub mod ids {
2228
2229pub const IDS: &str = r#"namespace osm {
2230struct Id
2231{
2232    value : u64 : 40;
2233}
2234}
2235
2236namespace osm {
2237archive Ids
2238{
2239    nodes : vector< .osm.Id >;
2240    ways : vector< .osm.Id >;
2241    relations : vector< .osm.Id >;
2242}
2243}
2244
2245"#;
2246
2247pub mod resources {
2248pub const NODES: &str = r#"namespace osm {
2249struct Id
2250{
2251    value : u64 : 40;
2252}
2253}
2254
2255namespace osm {
2256archive Ids
2257{
2258    nodes : vector< .osm.Id >;
2259}
2260}
2261
2262"#;
2263pub const WAYS: &str = r#"namespace osm {
2264struct Id
2265{
2266    value : u64 : 40;
2267}
2268}
2269
2270namespace osm {
2271archive Ids
2272{
2273    ways : vector< .osm.Id >;
2274}
2275}
2276
2277"#;
2278pub const RELATIONS: &str = r#"namespace osm {
2279struct Id
2280{
2281    value : u64 : 40;
2282}
2283}
2284
2285namespace osm {
2286archive Ids
2287{
2288    relations : vector< .osm.Id >;
2289}
2290}
2291
2292"#;
2293}
2294}
2295pub mod osm {
2296
2297pub const OSM: &str = r#"namespace osm {
2298struct Header
2299{
2300    coord_scale : i32 : 32;
2301    bbox_left : i32 : 32;
2302    bbox_right : i32 : 32;
2303    bbox_top : i32 : 32;
2304    bbox_bottom : i32 : 32;
2305    writingprogram_idx : u64 : 40;
2306    source_idx : u64 : 40;
2307    replication_timestamp : i64 : 64;
2308    replication_sequence_number : i64 : 64;
2309    replication_base_url_idx : u64 : 40;
2310}
2311}
2312
2313namespace osm {
2314struct Node
2315{
2316    lat : i32 : 32;
2317    lon : i32 : 32;
2318    @range( tags )
2319    tag_first_idx : u64 : 40;
2320}
2321}
2322
2323namespace osm {
2324struct Way
2325{
2326    @range( tags )
2327    tag_first_idx : u64 : 40;
2328    @range( refs )
2329    ref_first_idx : u64 : 40;
2330}
2331}
2332
2333namespace osm {
2334struct Relation
2335{
2336    @range( tags )
2337    tag_first_idx : u64 : 40;
2338}
2339}
2340
2341namespace osm {
2342const u64 INVALID_IDX = 1099511627775;
2343}
2344
2345namespace osm {
2346struct NodeMember
2347{
2348    @optional( .osm.INVALID_IDX )
2349    node_idx : u64 : 40;
2350    role_idx : u64 : 40;
2351}
2352}
2353
2354namespace osm {
2355struct WayMember
2356{
2357    @optional( .osm.INVALID_IDX )
2358    way_idx : u64 : 40;
2359    role_idx : u64 : 40;
2360}
2361}
2362
2363namespace osm {
2364struct RelationMember
2365{
2366    @optional( .osm.INVALID_IDX )
2367    relation_idx : u64 : 40;
2368    role_idx : u64 : 40;
2369}
2370}
2371
2372namespace osm {
2373struct Tag
2374{
2375    key_idx : u64 : 40;
2376    value_idx : u64 : 40;
2377}
2378}
2379
2380namespace osm {
2381struct TagIndex
2382{
2383    value : u64 : 40;
2384}
2385}
2386
2387namespace osm {
2388struct NodeIndex
2389{
2390    @optional( .osm.INVALID_IDX )
2391    value : u64 : 40;
2392}
2393}
2394
2395namespace osm {
2396struct Id
2397{
2398    value : u64 : 40;
2399}
2400}
2401
2402namespace osm {
2403archive Ids
2404{
2405    nodes : vector< .osm.Id >;
2406    ways : vector< .osm.Id >;
2407    relations : vector< .osm.Id >;
2408}
2409}
2410
2411namespace osm {
2412@bound_implicitly( Relations : .osm.Osm.relations, .osm.Osm.relation_members )
2413archive Osm
2414{
2415    @explicit_reference( .osm.Header.writingprogram_idx, .osm.Osm.stringtable )
2416    @explicit_reference( .osm.Header.source_idx, .osm.Osm.stringtable )
2417    @explicit_reference( .osm.Header.replication_base_url_idx, .osm.Osm.stringtable )
2418    header : .osm.Header;
2419    @explicit_reference( .osm.Node.tag_first_idx, .osm.Osm.tags_index )
2420    nodes : vector< .osm.Node >;
2421    @explicit_reference( .osm.Way.tag_first_idx, .osm.Osm.tags_index )
2422    @explicit_reference( .osm.Way.ref_first_idx, .osm.Osm.nodes_index )
2423    ways : vector< .osm.Way >;
2424    @explicit_reference( .osm.Relation.tag_first_idx, .osm.Osm.tags_index )
2425    relations : vector< .osm.Relation >;
2426    @explicit_reference( .osm.NodeMember.node_idx, .osm.Osm.nodes )
2427    @explicit_reference( .osm.NodeMember.role_idx, .osm.Osm.stringtable )
2428    @explicit_reference( .osm.WayMember.way_idx, .osm.Osm.ways )
2429    @explicit_reference( .osm.WayMember.role_idx, .osm.Osm.stringtable )
2430    @explicit_reference( .osm.RelationMember.relation_idx, .osm.Osm.relations )
2431    @explicit_reference( .osm.RelationMember.role_idx, .osm.Osm.stringtable )
2432    relation_members : multivector< 40, .osm.NodeMember, .osm.WayMember, .osm.RelationMember >;
2433    @explicit_reference( .osm.Tag.key_idx, .osm.Osm.stringtable )
2434    @explicit_reference( .osm.Tag.value_idx, .osm.Osm.stringtable )
2435    tags : vector< .osm.Tag >;
2436    @explicit_reference( .osm.TagIndex.value, .osm.Osm.tags )
2437    tags_index : vector< .osm.TagIndex >;
2438    @explicit_reference( .osm.NodeIndex.value, .osm.Osm.nodes )
2439    nodes_index : vector< .osm.NodeIndex >;
2440    stringtable : raw_data;
2441    @optional
2442    ids : archive .osm.Ids;
2443}
2444}
2445
2446"#;
2447
2448pub mod resources {
2449pub const HEADER: &str = r#"namespace osm {
2450struct Header
2451{
2452    coord_scale : i32 : 32;
2453    bbox_left : i32 : 32;
2454    bbox_right : i32 : 32;
2455    bbox_top : i32 : 32;
2456    bbox_bottom : i32 : 32;
2457    writingprogram_idx : u64 : 40;
2458    source_idx : u64 : 40;
2459    replication_timestamp : i64 : 64;
2460    replication_sequence_number : i64 : 64;
2461    replication_base_url_idx : u64 : 40;
2462}
2463}
2464
2465namespace osm {
2466archive Osm
2467{
2468    @explicit_reference( .osm.Header.writingprogram_idx, .osm.Osm.stringtable )
2469    @explicit_reference( .osm.Header.source_idx, .osm.Osm.stringtable )
2470    @explicit_reference( .osm.Header.replication_base_url_idx, .osm.Osm.stringtable )
2471    header : .osm.Header;
2472}
2473}
2474
2475"#;
2476pub const NODES: &str = r#"namespace osm {
2477struct Node
2478{
2479    lat : i32 : 32;
2480    lon : i32 : 32;
2481    @range( tags )
2482    tag_first_idx : u64 : 40;
2483}
2484}
2485
2486namespace osm {
2487archive Osm
2488{
2489    @explicit_reference( .osm.Node.tag_first_idx, .osm.Osm.tags_index )
2490    nodes : vector< .osm.Node >;
2491}
2492}
2493
2494"#;
2495pub const WAYS: &str = r#"namespace osm {
2496struct Way
2497{
2498    @range( tags )
2499    tag_first_idx : u64 : 40;
2500    @range( refs )
2501    ref_first_idx : u64 : 40;
2502}
2503}
2504
2505namespace osm {
2506archive Osm
2507{
2508    @explicit_reference( .osm.Way.tag_first_idx, .osm.Osm.tags_index )
2509    @explicit_reference( .osm.Way.ref_first_idx, .osm.Osm.nodes_index )
2510    ways : vector< .osm.Way >;
2511}
2512}
2513
2514"#;
2515pub const RELATIONS: &str = r#"namespace osm {
2516struct Relation
2517{
2518    @range( tags )
2519    tag_first_idx : u64 : 40;
2520}
2521}
2522
2523namespace osm {
2524archive Osm
2525{
2526    @explicit_reference( .osm.Relation.tag_first_idx, .osm.Osm.tags_index )
2527    relations : vector< .osm.Relation >;
2528}
2529}
2530
2531"#;
2532pub const RELATION_MEMBERS: &str = r#"namespace osm {
2533const u64 INVALID_IDX = 1099511627775;
2534}
2535
2536namespace osm {
2537struct NodeMember
2538{
2539    @optional( .osm.INVALID_IDX )
2540    node_idx : u64 : 40;
2541    role_idx : u64 : 40;
2542}
2543}
2544
2545namespace osm {
2546struct WayMember
2547{
2548    @optional( .osm.INVALID_IDX )
2549    way_idx : u64 : 40;
2550    role_idx : u64 : 40;
2551}
2552}
2553
2554namespace osm {
2555struct RelationMember
2556{
2557    @optional( .osm.INVALID_IDX )
2558    relation_idx : u64 : 40;
2559    role_idx : u64 : 40;
2560}
2561}
2562
2563namespace osm {
2564archive Osm
2565{
2566    @explicit_reference( .osm.NodeMember.node_idx, .osm.Osm.nodes )
2567    @explicit_reference( .osm.NodeMember.role_idx, .osm.Osm.stringtable )
2568    @explicit_reference( .osm.WayMember.way_idx, .osm.Osm.ways )
2569    @explicit_reference( .osm.WayMember.role_idx, .osm.Osm.stringtable )
2570    @explicit_reference( .osm.RelationMember.relation_idx, .osm.Osm.relations )
2571    @explicit_reference( .osm.RelationMember.role_idx, .osm.Osm.stringtable )
2572    relation_members : multivector< 40, .osm.NodeMember, .osm.WayMember, .osm.RelationMember >;
2573}
2574}
2575
2576"#;
2577pub const TAGS: &str = r#"namespace osm {
2578struct Tag
2579{
2580    key_idx : u64 : 40;
2581    value_idx : u64 : 40;
2582}
2583}
2584
2585namespace osm {
2586archive Osm
2587{
2588    @explicit_reference( .osm.Tag.key_idx, .osm.Osm.stringtable )
2589    @explicit_reference( .osm.Tag.value_idx, .osm.Osm.stringtable )
2590    tags : vector< .osm.Tag >;
2591}
2592}
2593
2594"#;
2595pub const TAGS_INDEX: &str = r#"namespace osm {
2596struct TagIndex
2597{
2598    value : u64 : 40;
2599}
2600}
2601
2602namespace osm {
2603archive Osm
2604{
2605    @explicit_reference( .osm.TagIndex.value, .osm.Osm.tags )
2606    tags_index : vector< .osm.TagIndex >;
2607}
2608}
2609
2610"#;
2611pub const NODES_INDEX: &str = r#"namespace osm {
2612const u64 INVALID_IDX = 1099511627775;
2613}
2614
2615namespace osm {
2616struct NodeIndex
2617{
2618    @optional( .osm.INVALID_IDX )
2619    value : u64 : 40;
2620}
2621}
2622
2623namespace osm {
2624archive Osm
2625{
2626    @explicit_reference( .osm.NodeIndex.value, .osm.Osm.nodes )
2627    nodes_index : vector< .osm.NodeIndex >;
2628}
2629}
2630
2631"#;
2632pub const STRINGTABLE: &str = r#"namespace osm {
2633archive Osm
2634{
2635    stringtable : raw_data;
2636}
2637}
2638
2639"#;
2640pub const IDS: &str = r#"namespace osm {
2641struct Id
2642{
2643    value : u64 : 40;
2644}
2645}
2646
2647namespace osm {
2648archive Ids
2649{
2650    nodes : vector< .osm.Id >;
2651    ways : vector< .osm.Id >;
2652    relations : vector< .osm.Id >;
2653}
2654}
2655
2656namespace osm {
2657archive Osm
2658{
2659    @optional
2660    ids : archive .osm.Ids;
2661}
2662}
2663
2664"#;
2665}
2666}
2667}
2668}
2669
2670#[doc(hidden)]
2671pub mod _builtin {
2672#[allow(unused_imports)]
2673use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
2674
2675
2676#[allow(missing_docs)]
2677pub mod multivector {
2678#[allow(unused_imports)]
2679use flatdata::{flatdata_read_bytes, flatdata_write_bytes};
2680
2681
2682/// Builtin type to for MultiVector index
2683#[repr(transparent)]
2684pub struct IndexType40 {
2685    data: [u8; 5],
2686}
2687
2688impl IndexType40 {
2689    /// Unsafe since the struct might not be self-contained
2690    pub unsafe fn new_unchecked( ) -> Self {
2691        Self{data : [0; 5]}
2692    }
2693}
2694
2695impl flatdata::Struct for IndexType40 {
2696    unsafe fn create_unchecked( ) -> Self {
2697        Self{data : [0; 5]}
2698    }
2699
2700    const SIZE_IN_BYTES: usize = 5;
2701    const IS_OVERLAPPING_WITH_NEXT : bool = true;
2702}
2703
2704impl flatdata::Overlap for IndexType40 {}
2705
2706impl IndexType40 {
2707    /// First element of the range [`range`].
2708    ///
2709    /// [`range`]: #method.range
2710    #[inline]
2711    pub fn value(&self) -> u64 {
2712        let value = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
2713        unsafe { std::mem::transmute::<u64, u64>(value) }
2714    }
2715
2716    #[inline]
2717    pub fn range(&self) -> std::ops::Range<u64> {
2718        let start = flatdata_read_bytes!(u64, self.data.as_ptr(), 0, 40);
2719        let end = flatdata_read_bytes!(u64, self.data.as_ptr(), 0 + 5 * 8, 40);
2720        start..end
2721    }
2722
2723}
2724
2725impl std::fmt::Debug for IndexType40 {
2726    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2727        f.debug_struct("IndexType40")
2728            .field("value", &self.value())
2729            .finish()
2730    }
2731}
2732
2733impl std::cmp::PartialEq for IndexType40 {
2734    #[inline]
2735    fn eq(&self, other: &Self) -> bool {
2736        self.value() == other.value()     }
2737}
2738
2739impl IndexType40 {
2740    /// First element of the range [`range`].
2741    ///
2742    /// [`range`]: struct.IndexType40Ref.html#method.range
2743    #[inline]
2744    #[allow(missing_docs)]
2745    pub fn set_value(&mut self, value: u64) {
2746        flatdata_write_bytes!(u64; value, self.data, 0, 40)
2747    }
2748
2749
2750    /// Copies the data from `other` into this struct.
2751    #[inline]
2752    pub fn fill_from(&mut self, other: &IndexType40) {
2753        self.set_value(other.value());
2754    }
2755}
2756
2757impl flatdata::IndexStruct for IndexType40 {
2758    #[inline]
2759    fn range(&self) -> std::ops::Range<usize> {
2760        let range = self.range();
2761        range.start as usize..range.end as usize
2762    }
2763
2764    #[inline]
2765    fn set_index(&mut self, value: usize) {
2766        self.set_value(value as u64);
2767    }
2768}
2769
2770
2771#[doc(hidden)]
2772pub mod schema {
2773}
2774}
2775
2776#[doc(hidden)]
2777pub mod schema {
2778}
2779}