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: f64

Implementations§

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

source

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);
source

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.

source

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.

source

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.

source

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 Clone for Person

source§

fn clone(&self) -> Person

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Display for Person

source§

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

source§

fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<Person> for Floor

source§

fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V