...

Text file src/github.com/google/flatbuffers/tests/monster_test/my_game/example/any_ambiguous_aliases_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#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
    13pub const ENUM_MIN_ANY_AMBIGUOUS_ALIASES: u8 = 0;
    14#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
    15pub const ENUM_MAX_ANY_AMBIGUOUS_ALIASES: u8 = 3;
    16#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
    17#[allow(non_camel_case_types)]
    18pub const ENUM_VALUES_ANY_AMBIGUOUS_ALIASES: [AnyAmbiguousAliases; 4] = [
    19  AnyAmbiguousAliases::NONE,
    20  AnyAmbiguousAliases::M1,
    21  AnyAmbiguousAliases::M2,
    22  AnyAmbiguousAliases::M3,
    23];
    24
    25#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
    26#[repr(transparent)]
    27pub struct AnyAmbiguousAliases(pub u8);
    28#[allow(non_upper_case_globals)]
    29impl AnyAmbiguousAliases {
    30  pub const NONE: Self = Self(0);
    31  pub const M1: Self = Self(1);
    32  pub const M2: Self = Self(2);
    33  pub const M3: Self = Self(3);
    34
    35  pub const ENUM_MIN: u8 = 0;
    36  pub const ENUM_MAX: u8 = 3;
    37  pub const ENUM_VALUES: &'static [Self] = &[
    38    Self::NONE,
    39    Self::M1,
    40    Self::M2,
    41    Self::M3,
    42  ];
    43  /// Returns the variant's name or "" if unknown.
    44  pub fn variant_name(self) -> Option<&'static str> {
    45    match self {
    46      Self::NONE => Some("NONE"),
    47      Self::M1 => Some("M1"),
    48      Self::M2 => Some("M2"),
    49      Self::M3 => Some("M3"),
    50      _ => None,
    51    }
    52  }
    53}
    54impl core::fmt::Debug for AnyAmbiguousAliases {
    55  fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
    56    if let Some(name) = self.variant_name() {
    57      f.write_str(name)
    58    } else {
    59      f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
    60    }
    61  }
    62}
    63impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
    64  type Inner = Self;
    65  #[inline]
    66  unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
    67    let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
    68    Self(b)
    69  }
    70}
    71
    72impl flatbuffers::Push for AnyAmbiguousAliases {
    73    type Output = AnyAmbiguousAliases;
    74    #[inline]
    75    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
    76        flatbuffers::emplace_scalar::<u8>(dst, self.0);
    77    }
    78}
    79
    80impl flatbuffers::EndianScalar for AnyAmbiguousAliases {
    81  type Scalar = u8;
    82  #[inline]
    83  fn to_little_endian(self) -> u8 {
    84    self.0.to_le()
    85  }
    86  #[inline]
    87  #[allow(clippy::wrong_self_convention)]
    88  fn from_little_endian(v: u8) -> Self {
    89    let b = u8::from_le(v);
    90    Self(b)
    91  }
    92}
    93
    94impl<'a> flatbuffers::Verifiable for AnyAmbiguousAliases {
    95  #[inline]
    96  fn run_verifier(
    97    v: &mut flatbuffers::Verifier, pos: usize
    98  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
    99    use self::flatbuffers::Verifiable;
   100    u8::run_verifier(v, pos)
   101  }
   102}
   103
   104impl flatbuffers::SimpleToVerifyInSlice for AnyAmbiguousAliases {}
   105pub struct AnyAmbiguousAliasesUnionTableOffset {}
   106
   107#[allow(clippy::upper_case_acronyms)]
   108#[non_exhaustive]
   109#[derive(Debug, Clone, PartialEq)]
   110pub enum AnyAmbiguousAliasesT {
   111  NONE,
   112  M1(Box<MonsterT>),
   113  M2(Box<MonsterT>),
   114  M3(Box<MonsterT>),
   115}
   116impl Default for AnyAmbiguousAliasesT {
   117  fn default() -> Self {
   118    Self::NONE
   119  }
   120}
   121impl AnyAmbiguousAliasesT {
   122  pub fn any_ambiguous_aliases_type(&self) -> AnyAmbiguousAliases {
   123    match self {
   124      Self::NONE => AnyAmbiguousAliases::NONE,
   125      Self::M1(_) => AnyAmbiguousAliases::M1,
   126      Self::M2(_) => AnyAmbiguousAliases::M2,
   127      Self::M3(_) => AnyAmbiguousAliases::M3,
   128    }
   129  }
   130  pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
   131    match self {
   132      Self::NONE => None,
   133      Self::M1(v) => Some(v.pack(fbb).as_union_value()),
   134      Self::M2(v) => Some(v.pack(fbb).as_union_value()),
   135      Self::M3(v) => Some(v.pack(fbb).as_union_value()),
   136    }
   137  }
   138  /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
   139  pub fn take_m1(&mut self) -> Option<Box<MonsterT>> {
   140    if let Self::M1(_) = self {
   141      let v = core::mem::replace(self, Self::NONE);
   142      if let Self::M1(w) = v {
   143        Some(w)
   144      } else {
   145        unreachable!()
   146      }
   147    } else {
   148      None
   149    }
   150  }
   151  /// If the union variant matches, return a reference to the MonsterT.
   152  pub fn as_m1(&self) -> Option<&MonsterT> {
   153    if let Self::M1(v) = self { Some(v.as_ref()) } else { None }
   154  }
   155  /// If the union variant matches, return a mutable reference to the MonsterT.
   156  pub fn as_m1_mut(&mut self) -> Option<&mut MonsterT> {
   157    if let Self::M1(v) = self { Some(v.as_mut()) } else { None }
   158  }
   159  /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
   160  pub fn take_m2(&mut self) -> Option<Box<MonsterT>> {
   161    if let Self::M2(_) = self {
   162      let v = core::mem::replace(self, Self::NONE);
   163      if let Self::M2(w) = v {
   164        Some(w)
   165      } else {
   166        unreachable!()
   167      }
   168    } else {
   169      None
   170    }
   171  }
   172  /// If the union variant matches, return a reference to the MonsterT.
   173  pub fn as_m2(&self) -> Option<&MonsterT> {
   174    if let Self::M2(v) = self { Some(v.as_ref()) } else { None }
   175  }
   176  /// If the union variant matches, return a mutable reference to the MonsterT.
   177  pub fn as_m2_mut(&mut self) -> Option<&mut MonsterT> {
   178    if let Self::M2(v) = self { Some(v.as_mut()) } else { None }
   179  }
   180  /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
   181  pub fn take_m3(&mut self) -> Option<Box<MonsterT>> {
   182    if let Self::M3(_) = self {
   183      let v = core::mem::replace(self, Self::NONE);
   184      if let Self::M3(w) = v {
   185        Some(w)
   186      } else {
   187        unreachable!()
   188      }
   189    } else {
   190      None
   191    }
   192  }
   193  /// If the union variant matches, return a reference to the MonsterT.
   194  pub fn as_m3(&self) -> Option<&MonsterT> {
   195    if let Self::M3(v) = self { Some(v.as_ref()) } else { None }
   196  }
   197  /// If the union variant matches, return a mutable reference to the MonsterT.
   198  pub fn as_m3_mut(&mut self) -> Option<&mut MonsterT> {
   199    if let Self::M3(v) = self { Some(v.as_mut()) } else { None }
   200  }
   201}

View as plain text