Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions samples/rust_generated/my_game/sample/color_generated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
use alloc::vec::Vec;
use alloc::string::String;
use alloc::boxed::Box;
use alloc::string::ToString;
use super::*;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_COLOR: i8 = 0;
Expand Down
11 changes: 7 additions & 4 deletions samples/rust_generated/my_game/sample/equipment_generated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
use alloc::vec::Vec;
use alloc::string::String;
use alloc::boxed::Box;
use alloc::string::ToString;
use super::*;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_EQUIPMENT: u8 = 0;
Expand Down Expand Up @@ -89,11 +93,10 @@ impl ::flatbuffers::SimpleToVerifyInSlice for Equipment {}
pub struct EquipmentUnionTableOffset {}

#[allow(clippy::upper_case_acronyms)]
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EquipmentT {
NONE,
Weapon(alloc::boxed::Box<WeaponT>),
Weapon(Box<WeaponT>),
}
impl Default for EquipmentT {
fn default() -> Self {
Expand All @@ -114,7 +117,7 @@ impl EquipmentT {
}
}
/// If the union variant matches, return the owned WeaponT, setting the union to NONE.
pub fn take_weapon(&mut self) -> Option<alloc::boxed::Box<WeaponT>> {
pub fn take_weapon(&mut self) -> Option<Box<WeaponT>> {
if let Self::Weapon(_) = self {
let v = ::core::mem::replace(self, Self::NONE);
if let Self::Weapon(w) = v {
Expand Down
21 changes: 12 additions & 9 deletions samples/rust_generated/my_game/sample/monster_generated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
use alloc::vec::Vec;
use alloc::string::String;
use alloc::boxed::Box;
use alloc::string::ToString;
use super::*;
pub enum MonsterOffset {}
#[derive(Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -63,7 +67,7 @@ impl<'a> Monster<'a> {
let mana = self.mana();
let hp = self.hp();
let name = self.name().map(|x| {
alloc::string::ToString::to_string(x)
x.to_string()
});
let inventory = self.inventory().map(|x| {
x.into_iter().collect()
Expand All @@ -74,7 +78,7 @@ impl<'a> Monster<'a> {
});
let equipped = match self.equipped_type() {
Equipment::NONE => EquipmentT::NONE,
Equipment::Weapon => EquipmentT::Weapon(alloc::boxed::Box::new(
Equipment::Weapon => EquipmentT::Weapon(Box::new(
self.equipped_as_weapon()
.expect("Invalid union table, expected `Equipment::Weapon`.")
.unpack()
Expand Down Expand Up @@ -326,18 +330,17 @@ impl ::core::fmt::Debug for Monster<'_> {
ds.finish()
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct MonsterT {
pub pos: Option<Vec3T>,
pub mana: i16,
pub hp: i16,
pub name: Option<alloc::string::String>,
pub inventory: Option<alloc::vec::Vec<u8>>,
pub name: Option<String>,
pub inventory: Option<Vec<u8>>,
pub color: Color,
pub weapons: Option<alloc::vec::Vec<WeaponT>>,
pub weapons: Option<Vec<WeaponT>>,
pub equipped: EquipmentT,
pub path: Option<alloc::vec::Vec<Vec3T>>,
pub path: Option<Vec<Vec3T>>,
}
impl Default for MonsterT {
fn default() -> Self {
Expand Down Expand Up @@ -371,12 +374,12 @@ impl MonsterT {
});
let color = self.color;
let weapons = self.weapons.as_ref().map(|x|{
let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
});
let equipped_type = self.equipped.equipment_type();
let equipped = self.equipped.pack(_fbb);
let path = self.path.as_ref().map(|x|{
let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
});
Monster::create(_fbb, &MonsterArgs{
pos,
Expand Down
4 changes: 4 additions & 0 deletions samples/rust_generated/my_game/sample/vec_3_generated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
use alloc::vec::Vec;
use alloc::string::String;
use alloc::boxed::Box;
use alloc::string::ToString;
use super::*;
// struct Vec3, aligned to 4
#[repr(transparent)]
Expand Down
11 changes: 7 additions & 4 deletions samples/rust_generated/my_game/sample/weapon_generated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
use alloc::vec::Vec;
use alloc::string::String;
use alloc::boxed::Box;
use alloc::string::ToString;
use super::*;
pub enum WeaponOffset {}
#[derive(Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -42,7 +46,7 @@ impl<'a> Weapon<'a> {

pub fn unpack(&self) -> WeaponT {
let name = self.name().map(|x| {
alloc::string::ToString::to_string(x)
x.to_string()
});
let damage = self.damage();
WeaponT {
Expand Down Expand Up @@ -129,10 +133,9 @@ impl ::core::fmt::Debug for Weapon<'_> {
ds.finish()
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WeaponT {
pub name: Option<alloc::string::String>,
pub name: Option<String>,
pub damage: i16,
}
impl Default for WeaponT {
Expand Down
Loading