summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorCasper <casperneo@uchicago.edu>2021-02-07 16:51:33 -0500
committerGitHub <noreply@github.com>2021-02-07 16:51:33 -0500
commit6f3e45eca1fde7a68cb72fd4499a3647f719c9db (patch)
tree0c3153b1cedc161e9f3ffab75a760382b2e7b45e /samples
parent815d3e820d4969af68800ddca5f1e6771c3622da (diff)
downloadflatbuffers-6f3e45eca1fde7a68cb72fd4499a3647f719c9db.tar.gz
flatbuffers-6f3e45eca1fde7a68cb72fd4499a3647f719c9db.tar.bz2
flatbuffers-6f3e45eca1fde7a68cb72fd4499a3647f719c9db.zip
Implement Rust object API defaults (#6444)
* Implment Rust object API defaults * satisfy return analysis * git clang format Co-authored-by: Casper Neo <cneo@google.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/monster_generated.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/samples/monster_generated.rs b/samples/monster_generated.rs
index cc2051e1..aae5c6c2 100644
--- a/samples/monster_generated.rs
+++ b/samples/monster_generated.rs
@@ -698,7 +698,7 @@ impl std::fmt::Debug for Monster<'_> {
}
}
#[non_exhaustive]
-#[derive(Debug, Clone, PartialEq, Default)]
+#[derive(Debug, Clone, PartialEq)]
pub struct MonsterT {
pub pos: Option<Vec3T>,
pub mana: i16,
@@ -710,6 +710,21 @@ pub struct MonsterT {
pub equipped: EquipmentT,
pub path: Option<Vec<Vec3T>>,
}
+impl Default for MonsterT {
+ fn default() -> Self {
+ Self {
+ pos: None,
+ mana: 150,
+ hp: 100,
+ name: None,
+ inventory: None,
+ color: Color::Blue,
+ weapons: None,
+ equipped: EquipmentT::NONE,
+ path: None,
+ }
+ }
+}
impl MonsterT {
pub fn pack<'b>(
&self,
@@ -864,11 +879,19 @@ impl std::fmt::Debug for Weapon<'_> {
}
}
#[non_exhaustive]
-#[derive(Debug, Clone, PartialEq, Default)]
+#[derive(Debug, Clone, PartialEq)]
pub struct WeaponT {
pub name: Option<String>,
pub damage: i16,
}
+impl Default for WeaponT {
+ fn default() -> Self {
+ Self {
+ name: None,
+ damage: 0,
+ }
+ }
+}
impl WeaponT {
pub fn pack<'b>(
&self,