elevator_core/components/access.rs
1//! Access control component for restricting rider stop access.
2
3use crate::entity::EntityId;
4use serde::{Deserialize, Serialize};
5use std::collections::HashSet;
6
7/// Per-rider access control: which stops the rider is allowed to visit.
8///
9/// When absent from a rider entity, the rider has unrestricted access.
10/// When present, only stops in [`allowed_stops`](Self::allowed_stops) are
11/// reachable — boarding is rejected with
12/// [`RejectionReason::AccessDenied`](crate::error::RejectionReason::AccessDenied)
13/// if the rider's current destination is not in the set.
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct AccessControl {
16 /// Set of stop `EntityId`s this rider may visit.
17 allowed_stops: HashSet<EntityId>,
18}
19
20impl AccessControl {
21 /// Create a new access control with the given set of allowed stops.
22 #[must_use]
23 pub const fn new(allowed_stops: HashSet<EntityId>) -> Self {
24 Self { allowed_stops }
25 }
26
27 /// Check if the rider can access the given stop.
28 #[must_use]
29 pub fn can_access(&self, stop: EntityId) -> bool {
30 self.allowed_stops.contains(&stop)
31 }
32
33 /// The set of allowed stop entity IDs.
34 #[must_use]
35 pub const fn allowed_stops(&self) -> &HashSet<EntityId> {
36 &self.allowed_stops
37 }
38}