pub struct MapSource { /* private fields */ }Expand description
A map-based source that looks up values by StatId.
Useful when you have a collection of stat values that you want to use as sources. Returns 0.0 for stats not in the map.
§Examples
use zzstat::source::{MapSource, StatSource};
use zzstat::{StatId, StatContext};
use std::collections::HashMap;
let mut values = HashMap::new();
values.insert(StatId::from_str("HP"), 100.0);
values.insert(StatId::from_str("MP"), 50.0);
let source = MapSource::new(values);
let context = StatContext::new();
assert_eq!(source.get_value(&StatId::from_str("HP"), &context), 100.0);
assert_eq!(source.get_value(&StatId::from_str("MP"), &context), 50.0);
assert_eq!(source.get_value(&StatId::from_str("ATK"), &context), 0.0);Implementations§
Source§impl MapSource
impl MapSource
Sourcepub fn new(values: HashMap<StatId, f64>) -> Self
pub fn new(values: HashMap<StatId, f64>) -> Self
Create a new MapSource from a HashMap.
§Examples
use zzstat::source::MapSource;
use zzstat::StatId;
use std::collections::HashMap;
let mut values = HashMap::new();
values.insert(StatId::from_str("HP"), 100.0);
let source = MapSource::new(values);Trait Implementations§
Auto Trait Implementations§
impl Freeze for MapSource
impl RefUnwindSafe for MapSource
impl Send for MapSource
impl Sync for MapSource
impl Unpin for MapSource
impl UnwindSafe for MapSource
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