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>
This commit is contained in:
Casper
2021-02-07 16:51:33 -05:00
committed by GitHub
parent 815d3e820d
commit 6f3e45eca1
8 changed files with 403 additions and 32 deletions

View File

@@ -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,