mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-11 07:27:27 +00:00
* Refactored Rust Generated code into a module directory. Each symbol will be generated into one file and then imported into a module. This breaks the "out_dir" pattern where some users would generate code in their target/ directory. Also, these objects are best used in their own module. It will be hard for users to share their own module structure with flatbuffers namespaces. There may be solutions to these drawbacks but that should be discussed. I don't want to overengineer here. * shadow error * try fix .bat file * fix .bat 2 * Restore accidentally deleted files * Fixed some DONOTSUBMITs and made Rust outdir pattern use symlinks. * fixed binary files * git clang format * make generated onefiles not public and fix .bat * reduced diff with master in generate_code.sh * fix shadowed variable * add object api flags to .bat * space * Removed extern crate and extra & * use statement * more clippy lints * format * Undo extern crate -> use change, it actually matters to our tests Co-authored-by: Casper Neo <cneo@google.com>
166 lines
3.9 KiB
Rust
166 lines
3.9 KiB
Rust
// automatically generated by the FlatBuffers compiler, do not modify
|
|
extern crate flatbuffers;
|
|
use std::mem;
|
|
use std::cmp::Ordering;
|
|
use self::flatbuffers::{EndianScalar, Follow};
|
|
use super::*;
|
|
// struct Ability, aligned to 4
|
|
#[repr(transparent)]
|
|
#[derive(Clone, Copy, PartialEq)]
|
|
pub struct Ability(pub [u8; 8]);
|
|
impl Default for Ability {
|
|
fn default() -> Self {
|
|
Self([0; 8])
|
|
}
|
|
}
|
|
impl std::fmt::Debug for Ability {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
f.debug_struct("Ability")
|
|
.field("id", &self.id())
|
|
.field("distance", &self.distance())
|
|
.finish()
|
|
}
|
|
}
|
|
|
|
impl flatbuffers::SimpleToVerifyInSlice for Ability {}
|
|
impl flatbuffers::SafeSliceAccess for Ability {}
|
|
impl<'a> flatbuffers::Follow<'a> for Ability {
|
|
type Inner = &'a Ability;
|
|
#[inline]
|
|
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
|
<&'a Ability>::follow(buf, loc)
|
|
}
|
|
}
|
|
impl<'a> flatbuffers::Follow<'a> for &'a Ability {
|
|
type Inner = &'a Ability;
|
|
#[inline]
|
|
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
|
flatbuffers::follow_cast_ref::<Ability>(buf, loc)
|
|
}
|
|
}
|
|
impl<'b> flatbuffers::Push for Ability {
|
|
type Output = Ability;
|
|
#[inline]
|
|
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
|
let src = unsafe {
|
|
::std::slice::from_raw_parts(self as *const Ability as *const u8, Self::size())
|
|
};
|
|
dst.copy_from_slice(src);
|
|
}
|
|
}
|
|
impl<'b> flatbuffers::Push for &'b Ability {
|
|
type Output = Ability;
|
|
|
|
#[inline]
|
|
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
|
let src = unsafe {
|
|
::std::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size())
|
|
};
|
|
dst.copy_from_slice(src);
|
|
}
|
|
}
|
|
|
|
impl<'a> flatbuffers::Verifiable for Ability {
|
|
#[inline]
|
|
fn run_verifier(
|
|
v: &mut flatbuffers::Verifier, pos: usize
|
|
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
|
use self::flatbuffers::Verifiable;
|
|
v.in_buffer::<Self>(pos)
|
|
}
|
|
}
|
|
impl<'a> Ability {
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub fn new(
|
|
id: u32,
|
|
distance: u32,
|
|
) -> Self {
|
|
let mut s = Self([0; 8]);
|
|
s.set_id(id);
|
|
s.set_distance(distance);
|
|
s
|
|
}
|
|
|
|
pub const fn get_fully_qualified_name() -> &'static str {
|
|
"MyGame.Example.Ability"
|
|
}
|
|
|
|
pub fn id(&self) -> u32 {
|
|
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
|
|
unsafe {
|
|
core::ptr::copy_nonoverlapping(
|
|
self.0[0..].as_ptr(),
|
|
mem.as_mut_ptr() as *mut u8,
|
|
core::mem::size_of::<u32>(),
|
|
);
|
|
mem.assume_init()
|
|
}.from_little_endian()
|
|
}
|
|
|
|
pub fn set_id(&mut self, x: u32) {
|
|
let x_le = x.to_little_endian();
|
|
unsafe {
|
|
core::ptr::copy_nonoverlapping(
|
|
&x_le as *const u32 as *const u8,
|
|
self.0[0..].as_mut_ptr(),
|
|
core::mem::size_of::<u32>(),
|
|
);
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
pub fn key_compare_less_than(&self, o: &Ability) -> bool {
|
|
self.id() < o.id()
|
|
}
|
|
|
|
#[inline]
|
|
pub fn key_compare_with_value(&self, val: u32) -> ::std::cmp::Ordering {
|
|
let key = self.id();
|
|
key.cmp(&val)
|
|
}
|
|
pub fn distance(&self) -> u32 {
|
|
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
|
|
unsafe {
|
|
core::ptr::copy_nonoverlapping(
|
|
self.0[4..].as_ptr(),
|
|
mem.as_mut_ptr() as *mut u8,
|
|
core::mem::size_of::<u32>(),
|
|
);
|
|
mem.assume_init()
|
|
}.from_little_endian()
|
|
}
|
|
|
|
pub fn set_distance(&mut self, x: u32) {
|
|
let x_le = x.to_little_endian();
|
|
unsafe {
|
|
core::ptr::copy_nonoverlapping(
|
|
&x_le as *const u32 as *const u8,
|
|
self.0[4..].as_mut_ptr(),
|
|
core::mem::size_of::<u32>(),
|
|
);
|
|
}
|
|
}
|
|
|
|
pub fn unpack(&self) -> AbilityT {
|
|
AbilityT {
|
|
id: self.id(),
|
|
distance: self.distance(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default)]
|
|
pub struct AbilityT {
|
|
pub id: u32,
|
|
pub distance: u32,
|
|
}
|
|
impl AbilityT {
|
|
pub fn pack(&self) -> Ability {
|
|
Ability::new(
|
|
self.id,
|
|
self.distance,
|
|
)
|
|
}
|
|
}
|
|
|