summaryrefslogtreecommitdiff
path: root/tests/more_defaults_generated.rs
diff options
context:
space:
mode:
authorCasper <casperneo@uchicago.edu>2021-04-06 07:23:45 -0400
committerGitHub <noreply@github.com>2021-04-06 07:23:45 -0400
commit261cf3b20473abdf95fc34da0827e4986f065c39 (patch)
treec10c9fc913d356708fac31765e8323aa8de786c4 /tests/more_defaults_generated.rs
parentcd67261bbab01b60c2407dcbf4736037aae5d8e4 (diff)
downloadflatbuffers-261cf3b20473abdf95fc34da0827e4986f065c39.tar.gz
flatbuffers-261cf3b20473abdf95fc34da0827e4986f065c39.tar.bz2
flatbuffers-261cf3b20473abdf95fc34da0827e4986f065c39.zip
Default-empty vectors of enums (#6505)
* disable clippy * Vector of enum default * swift and tests * git clang format * Rewrite enum parser checks * Remove Voids from more_defaults * vector enum swift * remove vector accessor from swift * clang format Co-authored-by: Casper Neo <cneo@google.com>
Diffstat (limited to 'tests/more_defaults_generated.rs')
-rw-r--r--tests/more_defaults_generated.rs140
1 files changed, 140 insertions, 0 deletions
diff --git a/tests/more_defaults_generated.rs b/tests/more_defaults_generated.rs
index 800677e4..afb74bd4 100644
--- a/tests/more_defaults_generated.rs
+++ b/tests/more_defaults_generated.rs
@@ -8,6 +8,94 @@ use std::cmp::Ordering;
extern crate flatbuffers;
use self::flatbuffers::EndianScalar;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+pub const ENUM_MIN_ABC: i32 = 0;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+pub const ENUM_MAX_ABC: i32 = 2;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+#[allow(non_camel_case_types)]
+pub const ENUM_VALUES_ABC: [ABC; 3] = [
+ ABC::A,
+ ABC::B,
+ ABC::C,
+];
+
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
+#[repr(transparent)]
+pub struct ABC(pub i32);
+#[allow(non_upper_case_globals)]
+impl ABC {
+ pub const A: Self = Self(0);
+ pub const B: Self = Self(1);
+ pub const C: Self = Self(2);
+
+ pub const ENUM_MIN: i32 = 0;
+ pub const ENUM_MAX: i32 = 2;
+ pub const ENUM_VALUES: &'static [Self] = &[
+ Self::A,
+ Self::B,
+ Self::C,
+ ];
+ /// Returns the variant's name or "" if unknown.
+ pub fn variant_name(self) -> Option<&'static str> {
+ match self {
+ Self::A => Some("A"),
+ Self::B => Some("B"),
+ Self::C => Some("C"),
+ _ => None,
+ }
+ }
+}
+impl std::fmt::Debug for ABC {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ if let Some(name) = self.variant_name() {
+ f.write_str(name)
+ } else {
+ f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
+ }
+ }
+}
+impl<'a> flatbuffers::Follow<'a> for ABC {
+ type Inner = Self;
+ #[inline]
+ fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+ let b = flatbuffers::read_scalar_at::<i32>(buf, loc);
+ Self(b)
+ }
+}
+
+impl flatbuffers::Push for ABC {
+ type Output = ABC;
+ #[inline]
+ fn push(&self, dst: &mut [u8], _rest: &[u8]) {
+ flatbuffers::emplace_scalar::<i32>(dst, self.0);
+ }
+}
+
+impl flatbuffers::EndianScalar for ABC {
+ #[inline]
+ fn to_little_endian(self) -> Self {
+ let b = i32::to_le(self.0);
+ Self(b)
+ }
+ #[inline]
+ fn from_little_endian(self) -> Self {
+ let b = i32::from_le(self.0);
+ Self(b)
+ }
+}
+
+impl<'a> flatbuffers::Verifiable for ABC {
+ #[inline]
+ fn run_verifier(
+ v: &mut flatbuffers::Verifier, pos: usize
+ ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
+ use self::flatbuffers::Verifiable;
+ i32::run_verifier(v, pos)
+ }
+}
+
+impl flatbuffers::SimpleToVerifyInSlice for ABC {}
pub enum MoreDefaultsOffset {}
#[derive(Copy, Clone, PartialEq)]
@@ -33,6 +121,8 @@ impl<'a> MoreDefaults<'a> {
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args MoreDefaultsArgs<'args>) -> flatbuffers::WIPOffset<MoreDefaults<'bldr>> {
let mut builder = MoreDefaultsBuilder::new(_fbb);
+ if let Some(x) = args.bools { builder.add_bools(x); }
+ if let Some(x) = args.abcs { builder.add_abcs(x); }
if let Some(x) = args.some_string { builder.add_some_string(x); }
if let Some(x) = args.empty_string { builder.add_empty_string(x); }
if let Some(x) = args.floats { builder.add_floats(x); }
@@ -57,17 +147,29 @@ impl<'a> MoreDefaults<'a> {
let x = self.some_string();
x.to_string()
};
+ let abcs = {
+ let x = self.abcs();
+ x.into_iter().collect()
+ };
+ let bools = {
+ let x = self.bools();
+ x.to_vec()
+ };
MoreDefaultsT {
ints,
floats,
empty_string,
some_string,
+ abcs,
+ bools,
}
}
pub const VT_INTS: flatbuffers::VOffsetT = 4;
pub const VT_FLOATS: flatbuffers::VOffsetT = 6;
pub const VT_EMPTY_STRING: flatbuffers::VOffsetT = 8;
pub const VT_SOME_STRING: flatbuffers::VOffsetT = 10;
+ pub const VT_ABCS: flatbuffers::VOffsetT = 12;
+ pub const VT_BOOLS: flatbuffers::VOffsetT = 14;
#[inline]
pub fn ints(&self) -> flatbuffers::Vector<'a, i32> {
@@ -85,6 +187,14 @@ impl<'a> MoreDefaults<'a> {
pub fn some_string(&self) -> &'a str {
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_SOME_STRING, Some(&"some")).unwrap()
}
+ #[inline]
+ pub fn abcs(&self) -> flatbuffers::Vector<'a, ABC> {
+ self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, ABC>>>(MoreDefaults::VT_ABCS, Some(Default::default())).unwrap()
+ }
+ #[inline]
+ pub fn bools(&self) -> &'a [bool] {
+ self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(MoreDefaults::VT_BOOLS, Some(Default::default())).map(|v| v.safe_slice()).unwrap()
+ }
}
impl flatbuffers::Verifiable for MoreDefaults<'_> {
@@ -98,6 +208,8 @@ impl flatbuffers::Verifiable for MoreDefaults<'_> {
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, f32>>>(&"floats", Self::VT_FLOATS, false)?
.visit_field::<flatbuffers::ForwardsUOffset<&str>>(&"empty_string", Self::VT_EMPTY_STRING, false)?
.visit_field::<flatbuffers::ForwardsUOffset<&str>>(&"some_string", Self::VT_SOME_STRING, false)?
+ .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, ABC>>>(&"abcs", Self::VT_ABCS, false)?
+ .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, bool>>>(&"bools", Self::VT_BOOLS, false)?
.finish();
Ok(())
}
@@ -107,6 +219,8 @@ pub struct MoreDefaultsArgs<'a> {
pub floats: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, f32>>>,
pub empty_string: Option<flatbuffers::WIPOffset<&'a str>>,
pub some_string: Option<flatbuffers::WIPOffset<&'a str>>,
+ pub abcs: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, ABC>>>,
+ pub bools: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, bool>>>,
}
impl<'a> Default for MoreDefaultsArgs<'a> {
#[inline]
@@ -116,6 +230,8 @@ impl<'a> Default for MoreDefaultsArgs<'a> {
floats: None,
empty_string: None,
some_string: None,
+ abcs: None,
+ bools: None,
}
}
}
@@ -141,6 +257,14 @@ impl<'a: 'b, 'b> MoreDefaultsBuilder<'a, 'b> {
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(MoreDefaults::VT_SOME_STRING, some_string);
}
#[inline]
+ pub fn add_abcs(&mut self, abcs: flatbuffers::WIPOffset<flatbuffers::Vector<'b , ABC>>) {
+ self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(MoreDefaults::VT_ABCS, abcs);
+ }
+ #[inline]
+ pub fn add_bools(&mut self, bools: flatbuffers::WIPOffset<flatbuffers::Vector<'b , bool>>) {
+ self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(MoreDefaults::VT_BOOLS, bools);
+ }
+ #[inline]
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> MoreDefaultsBuilder<'a, 'b> {
let start = _fbb.start_table();
MoreDefaultsBuilder {
@@ -162,6 +286,8 @@ impl std::fmt::Debug for MoreDefaults<'_> {
ds.field("floats", &self.floats());
ds.field("empty_string", &self.empty_string());
ds.field("some_string", &self.some_string());
+ ds.field("abcs", &self.abcs());
+ ds.field("bools", &self.bools());
ds.finish()
}
}
@@ -172,6 +298,8 @@ pub struct MoreDefaultsT {
pub floats: Vec<f32>,
pub empty_string: String,
pub some_string: String,
+ pub abcs: Vec<ABC>,
+ pub bools: Vec<bool>,
}
impl Default for MoreDefaultsT {
fn default() -> Self {
@@ -180,6 +308,8 @@ impl Default for MoreDefaultsT {
floats: Default::default(),
empty_string: "".to_string(),
some_string: "some".to_string(),
+ abcs: Default::default(),
+ bools: Default::default(),
}
}
}
@@ -204,11 +334,21 @@ impl MoreDefaultsT {
let x = &self.some_string;
_fbb.create_string(x)
});
+ let abcs = Some({
+ let x = &self.abcs;
+ _fbb.create_vector(x)
+ });
+ let bools = Some({
+ let x = &self.bools;
+ _fbb.create_vector(x)
+ });
MoreDefaults::create(_fbb, &MoreDefaultsArgs{
ints,
floats,
empty_string,
some_string,
+ abcs,
+ bools,
})
}
}