Person

Struct 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 duplicate 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§

§

impl Freeze for Person

§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

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,

Source§

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§

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>,

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V