Skip to content

Commit 8f010bb

Browse files
committed
Avoid using enum = null for older flatc versions (ubuntu 22.04)
1 parent d348bce commit 8f010bb

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

schema/lrs.fbs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ table Node {
5252
connections:[Connection] (required);
5353
}
5454

55-
enum Endpoint : byte { Begin = 1, End = 2 }
55+
enum Endpoint : byte { Unknown = 0, Begin = 1, End = 2 }
5656
/// A connection links a node to a segment
5757
table Connection {
5858
properties:[Property];
5959

6060
segment_index:uint64;
6161
/// A segment is oriented. The endpoint indicates what end of the segment is connected to the node
62-
endpoint:Endpoint = null;
62+
endpoint:Endpoint;
6363
}
6464

6565
/// A traversal is a path in a network.
@@ -143,7 +143,7 @@ enum GeometryType : byte { Geographic = 1, Schematic = 2 }
143143
table GeometryView {
144144
properties:[Property];
145145

146-
geometry_type:GeometryType = null;
146+
geometry_type:GeometryType = Geographic;
147147
anchors:[AnchorGeometry] (required);
148148
/// Must be the same size as the top level network array
149149
networks:[NetworkGeometry] (required);

src/lrs_generated.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ extern crate flatbuffers;
1010
use self::flatbuffers::{EndianScalar, Follow};
1111

1212
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
13-
pub const ENUM_MIN_ENDPOINT: i8 = 1;
13+
pub const ENUM_MIN_ENDPOINT: i8 = 0;
1414
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
1515
pub const ENUM_MAX_ENDPOINT: i8 = 2;
1616
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
1717
#[allow(non_camel_case_types)]
18-
pub const ENUM_VALUES_ENDPOINT: [Endpoint; 2] = [
18+
pub const ENUM_VALUES_ENDPOINT: [Endpoint; 3] = [
19+
Endpoint::Unknown,
1920
Endpoint::Begin,
2021
Endpoint::End,
2122
];
@@ -25,18 +26,21 @@ pub const ENUM_VALUES_ENDPOINT: [Endpoint; 2] = [
2526
pub struct Endpoint(pub i8);
2627
#[allow(non_upper_case_globals)]
2728
impl Endpoint {
29+
pub const Unknown: Self = Self(0);
2830
pub const Begin: Self = Self(1);
2931
pub const End: Self = Self(2);
3032

31-
pub const ENUM_MIN: i8 = 1;
33+
pub const ENUM_MIN: i8 = 0;
3234
pub const ENUM_MAX: i8 = 2;
3335
pub const ENUM_VALUES: &'static [Self] = &[
36+
Self::Unknown,
3437
Self::Begin,
3538
Self::End,
3639
];
3740
/// Returns the variant's name or "" if unknown.
3841
pub fn variant_name(self) -> Option<&'static str> {
3942
match self {
43+
Self::Unknown => Some("Unknown"),
4044
Self::Begin => Some("Begin"),
4145
Self::End => Some("End"),
4246
_ => None,
@@ -1497,7 +1501,7 @@ impl<'a> Connection<'a> {
14971501
let mut builder = ConnectionBuilder::new(_fbb);
14981502
builder.add_segment_index(args.segment_index);
14991503
if let Some(x) = args.properties { builder.add_properties(x); }
1500-
if let Some(x) = args.endpoint { builder.add_endpoint(x); }
1504+
builder.add_endpoint(args.endpoint);
15011505
builder.finish()
15021506
}
15031507

@@ -1518,11 +1522,11 @@ impl<'a> Connection<'a> {
15181522
}
15191523
/// A segment is oriented. The endpoint indicates what end of the segment is connected to the node
15201524
#[inline]
1521-
pub fn endpoint(&self) -> Option<Endpoint> {
1525+
pub fn endpoint(&self) -> Endpoint {
15221526
// Safety:
15231527
// Created from valid Table for this object
15241528
// which contains a valid value in this slot
1525-
unsafe { self._tab.get::<Endpoint>(Connection::VT_ENDPOINT, None)}
1529+
unsafe { self._tab.get::<Endpoint>(Connection::VT_ENDPOINT, Some(Endpoint::Unknown)).unwrap()}
15261530
}
15271531
}
15281532

@@ -1543,15 +1547,15 @@ impl flatbuffers::Verifiable for Connection<'_> {
15431547
pub struct ConnectionArgs<'a> {
15441548
pub properties: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Property<'a>>>>>,
15451549
pub segment_index: u64,
1546-
pub endpoint: Option<Endpoint>,
1550+
pub endpoint: Endpoint,
15471551
}
15481552
impl<'a> Default for ConnectionArgs<'a> {
15491553
#[inline]
15501554
fn default() -> Self {
15511555
ConnectionArgs {
15521556
properties: None,
15531557
segment_index: 0,
1554-
endpoint: None,
1558+
endpoint: Endpoint::Unknown,
15551559
}
15561560
}
15571561
}
@@ -1571,7 +1575,7 @@ impl<'a: 'b, 'b> ConnectionBuilder<'a, 'b> {
15711575
}
15721576
#[inline]
15731577
pub fn add_endpoint(&mut self, endpoint: Endpoint) {
1574-
self.fbb_.push_slot_always::<Endpoint>(Connection::VT_ENDPOINT, endpoint);
1578+
self.fbb_.push_slot::<Endpoint>(Connection::VT_ENDPOINT, endpoint, Endpoint::Unknown);
15751579
}
15761580
#[inline]
15771581
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> ConnectionBuilder<'a, 'b> {
@@ -2134,7 +2138,7 @@ impl<'a> GeometryView<'a> {
21342138
if let Some(x) = args.networks { builder.add_networks(x); }
21352139
if let Some(x) = args.anchors { builder.add_anchors(x); }
21362140
if let Some(x) = args.properties { builder.add_properties(x); }
2137-
if let Some(x) = args.geometry_type { builder.add_geometry_type(x); }
2141+
builder.add_geometry_type(args.geometry_type);
21382142
builder.finish()
21392143
}
21402144

@@ -2147,11 +2151,11 @@ impl<'a> GeometryView<'a> {
21472151
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Property>>>>(GeometryView::VT_PROPERTIES, None)}
21482152
}
21492153
#[inline]
2150-
pub fn geometry_type(&self) -> Option<GeometryType> {
2154+
pub fn geometry_type(&self) -> GeometryType {
21512155
// Safety:
21522156
// Created from valid Table for this object
21532157
// which contains a valid value in this slot
2154-
unsafe { self._tab.get::<GeometryType>(GeometryView::VT_GEOMETRY_TYPE, None)}
2158+
unsafe { self._tab.get::<GeometryType>(GeometryView::VT_GEOMETRY_TYPE, Some(GeometryType::Geographic)).unwrap()}
21552159
}
21562160
#[inline]
21572161
pub fn anchors(&self) -> flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<AnchorGeometry<'a>>> {
@@ -2187,7 +2191,7 @@ impl flatbuffers::Verifiable for GeometryView<'_> {
21872191
}
21882192
pub struct GeometryViewArgs<'a> {
21892193
pub properties: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Property<'a>>>>>,
2190-
pub geometry_type: Option<GeometryType>,
2194+
pub geometry_type: GeometryType,
21912195
pub anchors: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<AnchorGeometry<'a>>>>>,
21922196
pub networks: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<NetworkGeometry<'a>>>>>,
21932197
}
@@ -2196,7 +2200,7 @@ impl<'a> Default for GeometryViewArgs<'a> {
21962200
fn default() -> Self {
21972201
GeometryViewArgs {
21982202
properties: None,
2199-
geometry_type: None,
2203+
geometry_type: GeometryType::Geographic,
22002204
anchors: None, // required field
22012205
networks: None, // required field
22022206
}
@@ -2214,7 +2218,7 @@ impl<'a: 'b, 'b> GeometryViewBuilder<'a, 'b> {
22142218
}
22152219
#[inline]
22162220
pub fn add_geometry_type(&mut self, geometry_type: GeometryType) {
2217-
self.fbb_.push_slot_always::<GeometryType>(GeometryView::VT_GEOMETRY_TYPE, geometry_type);
2221+
self.fbb_.push_slot::<GeometryType>(GeometryView::VT_GEOMETRY_TYPE, geometry_type, GeometryType::Geographic);
22182222
}
22192223
#[inline]
22202224
pub fn add_anchors(&mut self, anchors: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<AnchorGeometry<'b >>>>) {

0 commit comments

Comments
 (0)