pub struct Config {
pub mappings: Vec<Mapping>,
pub overrides: Vec<Override>,
}Expand description
Configuration for timetable formatting and room mappings.
Loaded from a TOML file containing room-to-department mappings and optional per-lesson overrides.
Fields§
§mappings: Vec<Mapping>Room-to-department mapping rules
overrides: Vec<Override>Per-week/day/period lesson overrides
Implementations§
Source§impl Config
impl Config
Sourcepub fn load(path: &Path) -> Result<Self, ConfigError>
pub fn load(path: &Path) -> Result<Self, ConfigError>
Load configuration from a TOML file.
§Arguments
path- Path to the config.toml file
§Returns
A parsed Config structure.
§Errors
Returns ConfigError if:
- The file cannot be read
- The TOML syntax is invalid
- Required fields are missing
§Example
use timetable_core::config::Config;
use std::path::Path;
let config = Config::load(Path::new("config.toml"))?;
println!("Loaded {} room mappings", config.mappings.len());Sourcepub fn get_style_for_room(&self, room_code: &str) -> Option<&Mapping>
pub fn get_style_for_room(&self, room_code: &str) -> Option<&Mapping>
Find the mapping for a given room code.
Returns the mapping with the longest matching prefix. If both ‘MA’ and ‘MA1’ are configured, room ‘MA10’ matches ‘MA1’ (3 chars) over ‘MA’ (2 chars), regardless of configuration order.
§Arguments
room_code- Room code to look up (e.g., “MA3”, “SC8”)
§Returns
The matching Mapping, or None if no prefix matches.
§Example
if let Some(mapping) = config.get_style_for_room("MA3") {
println!("Room MA3 maps to: {}", mapping.map_id);
}Sourcepub fn apply_overrides(&self, weeks: &mut [Week])
pub fn apply_overrides(&self, weeks: &mut [Week])
Apply configured overrides to parsed weeks.
Modifies lessons in-place based on override rules. Each override specifies a week, day, and period, and can update any combination of subject, room, teacher, or class code.
§Arguments
weeks- Mutable slice of week data to modify
§Warnings
Prints warnings to stderr if:
- Week number is out of range
- Day or period name is invalid
- No matching lesson is found for an override
§Example
let config = Config::load(Path::new("config.toml"))?;
let mut weeks = parse_pdf(Path::new("input/timetable.pdf"))?;
config.apply_overrides(&mut weeks);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more