...

Text file src/github.com/google/flatbuffers/tests/monster_test/my_game/example/struct_of_structs_generated.rs

Documentation: github.com/google/flatbuffers/tests/monster_test/my_game/example

     1// automatically generated by the FlatBuffers compiler, do not modify
     2// @generated
     3extern crate alloc;
     4extern crate flatbuffers;
     5use alloc::boxed::Box;
     6use alloc::string::{String, ToString};
     7use alloc::vec::Vec;
     8use core::mem;
     9use core::cmp::Ordering;
    10use self::flatbuffers::{EndianScalar, Follow};
    11use super::*;
    12// struct StructOfStructs, aligned to 4
    13#[repr(transparent)]
    14#[derive(Clone, Copy, PartialEq)]
    15pub struct StructOfStructs(pub [u8; 20]);
    16impl Default for StructOfStructs { 
    17  fn default() -> Self { 
    18    Self([0; 20])
    19  }
    20}
    21impl core::fmt::Debug for StructOfStructs {
    22  fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
    23    f.debug_struct("StructOfStructs")
    24      .field("a", &self.a())
    25      .field("b", &self.b())
    26      .field("c", &self.c())
    27      .finish()
    28  }
    29}
    30
    31impl flatbuffers::SimpleToVerifyInSlice for StructOfStructs {}
    32impl<'a> flatbuffers::Follow<'a> for StructOfStructs {
    33  type Inner = &'a StructOfStructs;
    34  #[inline]
    35  unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
    36    <&'a StructOfStructs>::follow(buf, loc)
    37  }
    38}
    39impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructs {
    40  type Inner = &'a StructOfStructs;
    41  #[inline]
    42  unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
    43    flatbuffers::follow_cast_ref::<StructOfStructs>(buf, loc)
    44  }
    45}
    46impl<'b> flatbuffers::Push for StructOfStructs {
    47    type Output = StructOfStructs;
    48    #[inline]
    49    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
    50        let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
    51        dst.copy_from_slice(src);
    52    }
    53}
    54
    55impl<'a> flatbuffers::Verifiable for StructOfStructs {
    56  #[inline]
    57  fn run_verifier(
    58    v: &mut flatbuffers::Verifier, pos: usize
    59  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
    60    use self::flatbuffers::Verifiable;
    61    v.in_buffer::<Self>(pos)
    62  }
    63}
    64
    65impl<'a> StructOfStructs {
    66  #[allow(clippy::too_many_arguments)]
    67  pub fn new(
    68    a: &Ability,
    69    b: &Test,
    70    c: &Ability,
    71  ) -> Self {
    72    let mut s = Self([0; 20]);
    73    s.set_a(a);
    74    s.set_b(b);
    75    s.set_c(c);
    76    s
    77  }
    78
    79  pub const fn get_fully_qualified_name() -> &'static str {
    80    "MyGame.Example.StructOfStructs"
    81  }
    82
    83  pub fn a(&self) -> &Ability {
    84    // Safety:
    85    // Created from a valid Table for this object
    86    // Which contains a valid struct in this slot
    87    unsafe { &*(self.0[0..].as_ptr() as *const Ability) }
    88  }
    89
    90  #[allow(clippy::identity_op)]
    91  pub fn set_a(&mut self, x: &Ability) {
    92    self.0[0..0 + 8].copy_from_slice(&x.0)
    93  }
    94
    95  pub fn b(&self) -> &Test {
    96    // Safety:
    97    // Created from a valid Table for this object
    98    // Which contains a valid struct in this slot
    99    unsafe { &*(self.0[8..].as_ptr() as *const Test) }
   100  }
   101
   102  #[allow(clippy::identity_op)]
   103  pub fn set_b(&mut self, x: &Test) {
   104    self.0[8..8 + 4].copy_from_slice(&x.0)
   105  }
   106
   107  pub fn c(&self) -> &Ability {
   108    // Safety:
   109    // Created from a valid Table for this object
   110    // Which contains a valid struct in this slot
   111    unsafe { &*(self.0[12..].as_ptr() as *const Ability) }
   112  }
   113
   114  #[allow(clippy::identity_op)]
   115  pub fn set_c(&mut self, x: &Ability) {
   116    self.0[12..12 + 8].copy_from_slice(&x.0)
   117  }
   118
   119  pub fn unpack(&self) -> StructOfStructsT {
   120    StructOfStructsT {
   121      a: self.a().unpack(),
   122      b: self.b().unpack(),
   123      c: self.c().unpack(),
   124    }
   125  }
   126}
   127
   128#[derive(Debug, Clone, PartialEq, Default)]
   129pub struct StructOfStructsT {
   130  pub a: AbilityT,
   131  pub b: TestT,
   132  pub c: AbilityT,
   133}
   134impl StructOfStructsT {
   135  pub fn pack(&self) -> StructOfStructs {
   136    StructOfStructs::new(
   137      &self.a.pack(),
   138      &self.b.pack(),
   139      &self.c.pack(),
   140    )
   141  }
   142}
   143

View as plain text