pub struct Elevator {
    pub floor_on: usize,
    pub moving_up: bool,
    pub stopped: bool,
    pub people: Vec<Person>,
    /* private fields */
}
Expand description

Elevator struct

An Elevator is aggregated by buildings, and transports people between floors. The Elevator struct generally should not be directly instantiated; instead it should be managed via the Building type and ElevatorController implementations.

Fields§

§floor_on: usize§moving_up: bool§stopped: bool§people: Vec<Person>

Implementations§

source§

impl Elevator

Elevator type implementation

The following functions are used by Building and Controller types as well as Elevators implementations to update and control the behavior of an Elevator.

source

pub fn from(energy_up: f64, energy_down: f64, energy_coef: f64) -> Elevator

Initialize a new elevator given the elevator’s energy spent moving up, energy spent moving down, and energy coefficient (additional energy spent per person transported). The elevator is initialized stopped on the first floor with no people.

Example
let energy_up: f64 = 5.0_f64;
let energy_down: f64 = 2.5_f64;
let energy_coef: f64 = 0.5_f64;
let my_elev: Elevator = Elevator::from(energy_up, energy_down, energy_coef);
source

pub fn get_energy_spent(&mut self) -> f64

Calculate the total energy spent (as an f64) while the elevator is moving. If the elevator is not moving then return 0.0_f64.

source

pub fn update_floor(&mut self) -> usize

Use the stopped and moving_up properties of the elevator to update the elevator’s floor index. If stopped, then no change. If moving up then increment the floor_on by 1_usize. If moving down then decrement the floor_on by 1_usize.

source

pub fn get_nearest_dest_floor(&self) -> (usize, usize)

If there are people on the elevator, this returns the nearest destination floor among those people represented as a length-2 tuple of usizes. The first element is the destination floor, and the second is the distance to the floor. If there are no people on the floor, it returns (0_usize, 0_usize).

source

pub fn flush_people_leaving_elevator(&mut self) -> Vec<Person>

If the elevator is stopped, this function returns a Vec<Person> containing the people on the elevator whose destination floor is the current floor. If the elevator is not stopped, this function returns an empty vector.

Trait Implementations§

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 People for Elevator

source§

fn get_dest_floors(&self) -> Vec<usize>

Determines the destination floors for all people and returns it as a vector.

source§

fn get_num_people(&self) -> usize

Determines the total number of people and returns it as a usize.

source§

fn get_num_people_waiting(&self) -> usize

Determines the number of people waiting, that is, not at their desired floor.

source§

fn get_aggregate_wait_time(&self) -> usize

Reads the wait times from people waiting/not at their desired floor and aggregates the total into a usize.

source§

fn are_people_waiting(&self) -> bool

Determines whether anyone in the collection of people are going to a given floor, and returns a bool which is true if so, and false if not.

source§

fn are_people_going_to_floor(&self, floor_index: usize) -> bool

Determines whether anyone in the collection of people is waiting/not at their desired floor, and returns a bool which is true if so, and false if not.

source§

fn increment_wait_times(&mut self)

Increments the wait times (by 1_usize) among all people waiting/not at their desired floor.

source§

fn reset_wait_times(&mut self)

Resets the wait times (to 0_usize) among all people who have a nonzero wait time and are on their desired floor.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 SPwhere 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, U> TryFrom<U> for Twhere 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 Twhere 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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V