pub enum Material {
Consumable(Consumable),
NonConsumable(NonConsumable),
}Expand description
Represents a material resource that can be used in a project. It can be either consumable or non-consumable.
Variants§
Consumable(Consumable)
A consumable resource is a material that needs to be resupplied after use.
NonConsumable(NonConsumable)
A non-consumable resource is a material that does not need to be resupplied after use.
Implementations§
Source§impl Material
impl Material
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Returns a consumable material by default, with the given name.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the name of the material.
§Example
use planter_core::resources::Material;
let material = Material::new("Steel".to_owned());
assert_eq!(material.name(), "Steel");Sourcepub fn update_name(&mut self, name: impl Into<String>)
pub fn update_name(&mut self, name: impl Into<String>)
Updates the name of the material.
§Example
use planter_core::resources::Material;
let mut material = Material::new("Steel".to_owned());
material.update_name("Iron".to_owned());
assert_eq!(material.name(), "Iron");Sourcepub fn quantity(&self) -> Option<u16>
pub fn quantity(&self) -> Option<u16>
Returns the quantity of materials.
§Example
use planter_core::resources::Material;
let material = Material::new("Steel".to_owned());
assert_eq!(material.quantity(), None);Sourcepub fn update_quantity(&mut self, quantity: u16)
pub fn update_quantity(&mut self, quantity: u16)
Updates the quantity of materials.
§Example
use planter_core::resources::Material;
let mut material = Material::new("Steel".to_owned());
material.update_quantity(3);
assert_eq!(material.quantity(), Some(3));Sourcepub fn remove_quantity(&mut self)
pub fn remove_quantity(&mut self)
Remove the quantity of materials.
§Example
use planter_core::resources::Material;
let mut material = Material::new("Steel".to_owned());
material.update_quantity(3);
assert_eq!(material.quantity(), Some(3));
material.remove_quantity();
assert_eq!(material.quantity(), None);Sourcepub fn cost_per_unit(&self) -> Option<u16>
pub fn cost_per_unit(&self) -> Option<u16>
Returns the cost per unit of the material.
§Example
use planter_core::resources::Material;
let material = Material::new("Steel".to_owned());
assert_eq!(material.cost_per_unit(), None);Sourcepub fn update_cost_per_unit(&mut self, cost_per_unit: u16)
pub fn update_cost_per_unit(&mut self, cost_per_unit: u16)
Updates the cost per unit of the material.
§Example
use planter_core::resources::Material;
let mut material = Material::new("Steel".to_owned());
material.update_cost_per_unit(3);
assert_eq!(material.cost_per_unit(), Some(3));Sourcepub fn remove_cost_per_unit(&mut self)
pub fn remove_cost_per_unit(&mut self)
Remove the cost per unit of the material.
§Example
use planter_core::resources::Material;
let mut material = Material::new("Steel".to_owned());
material.update_cost_per_unit(3);
assert_eq!(material.cost_per_unit(), Some(3));
material.remove_cost_per_unit();
assert_eq!(material.cost_per_unit(), None);Trait Implementations§
impl Eq for Material
impl StructuralPartialEq for Material
Auto Trait Implementations§
impl Freeze for Material
impl RefUnwindSafe for Material
impl Send for Material
impl Sync for Material
impl Unpin for Material
impl UnwindSafe for Material
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more