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
§Person type implementation
The following functions are used by Elevator/Elevators, Floor/Floors, and
Building types to randomly generate the behavior of Persons
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 Freeze for Person
impl RefUnwindSafe for Person
impl Send for Person
impl Sync for Person
impl Unpin for Person
impl UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.