Struct elevate_lib::person::Person
source · pub struct Person {
pub floor_on: usize,
pub floor_to: usize,
pub is_leaving: bool,
pub wait_time: usize,
pub p_out: f64,
pub p_tip: f64,
/* private fields */
}Expand description
§Person struct
A Person is aggregated by floors and elevators, and transported between floors
by elevators. The person struct generally should not be directly instantiated;
instead it should be managed in aggregate via the Building type.
Fields§
§floor_on: usize§floor_to: usize§is_leaving: bool§wait_time: usize§p_out: f64§p_tip: f64Implementations§
source§impl Person
impl Person
§Person type implementation
The following functions are used by Elevator/Elevators, Floor/Floors, and
Building types to randomly generate the behavior of Persons
sourcepub fn from(
p_out: f64,
p_tip: f64,
num_floors: usize,
rng: &mut impl Rng
) -> Person
pub fn from( p_out: f64, p_tip: f64, num_floors: usize, rng: &mut impl Rng ) -> Person
Initialize a new person given that persons probability of leaving, the number of floors in the building, and an Rng implementation to randomize the person’s destination floor
§Example
let p_out: f64 = 0.05_f64; //Must be between 0 and 1
let p_tip: f64 = 0.2_f64; //Must be between 0 and 1
let num_floors: usize = 5_usize;
let my_rng = rand::thread_rng(); //From rand library
let my_pers: Person = Person::from(p_out, num_floors, &mut my_rng);sourcepub fn gen_is_leaving(&mut self, rng: &mut impl Rng) -> bool
pub fn gen_is_leaving(&mut self, rng: &mut impl Rng) -> bool
Sample a person’s dst_out distribution to update the person’s is_leaving
property randomly and return the result as a bool. Or if the person is already
leaving then return the property as is.
sourcepub fn gen_tip(&self, rng: &mut impl Rng) -> bool
pub fn gen_tip(&self, rng: &mut impl Rng) -> bool
Sample a person’s dst_tip distribution to determine whether or not they will
decide to tip.
sourcepub fn increment_wait_time(&mut self)
pub fn increment_wait_time(&mut self)
Increment a person’s wait_time property by 1_usize. Generally this should be
called by Elevator/Elevators, Floor/Floors, and Building types aggregating
Persons when the Person is not at their desired floor.
sourcepub fn reset_wait_time(&mut self)
pub fn reset_wait_time(&mut self)
Reset a person’s wait_time property to 0_usize. Generally this should be
called by Elevator/Elevators, Floor/Floors, and Building types aggregating
Persons when the Person finally reaches their desired floor.
Trait Implementations§
source§impl Display for Person
impl Display for Person
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Format a Person as a string. If a person is not at their desired floor then display
the person’s current and desired floor like so: Person 2 -> 4. If the person is at
their desired floor then just display their current floor like so: Person 4.
§Example
println!("{}", my_pers);source§impl Extend<Person> for Elevator
impl Extend<Person> for Elevator
source§fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl Extend<Person> for Floor
impl Extend<Person> for Floor
source§fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Auto Trait Implementations§
impl RefUnwindSafe for Person
impl Send for Person
impl Sync for Person
impl Unpin for Person
impl UnwindSafe for Person
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
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.