Struct XmlManager

Source
pub struct XmlManager;
Expand description

Structure responsible for managing XML file reading and parsing.

Implementations§

Source§

impl XmlManager

Source

pub fn read_xml(path: &str) -> Rawdata

Reads an XML file and parses into a Rawdata struct.

This function opens the specified XML file, parses it using roxmltree, and fills a Rawdata struct with information about the instance name, teams, slots, distances, capacity constraints, and separation constraints.

The XML elements are mapped as follows:

  • <InstanceName>Rawdata.instance_name
  • <team>Rawdata.teams
  • <slot>Rawdata.slots
  • <distance>Rawdata.distances
  • Elements starting with "CA"Rawdata.capacity_constraints
  • Elements starting with "SE"Rawdata.separation_constraints
§Arguments
  • path - A string slice representing the path to the XML file.
§Returns

A Rawdata struct containing all parsed information from the XML.

§Panics

This function will panic if the XML file cannot be opened or parsed.

§Example
let raw_data = read_xml("instances/example.xml");
println!("Instance name: {}", raw_data.instance_name);
println!("Number of teams: {}", raw_data.teams.len());
Source

fn parse_team(node: &Node<'_, '_>) -> Team

Parses a <Team> XML node and converts it into a Team struct.

This function reads the attributes of the given XML node and fills the corresponding fields in Team. If a numeric attribute is missing or cannot be parsed, it defaults to 0.

§Arguments
  • node - A reference to a roxmltree::Node representing the <Team> element.
§Returns

A Team struct populated with the parsed values.

§Example
let doc = roxmltree::Document::parse(r#"<Team id="5" league="1" name="Eagles" teamGroups="2"/>"#).unwrap();
let node = doc.root_element();
let team = parse_team(&node);
assert_eq!(team.id, 5);
assert_eq!(team.league, 1);
assert_eq!(team.name, "Eagles".to_string());
assert_eq!(team.team_groups, 2);
Source

fn parse_slot(node: &Node<'_, '_>) -> Slot

Parses a <Slot> XML node and converts it into a Slot struct.

This function reads the attributes of the given XML node and fills the corresponding fields in Slot. If an attribute is missing or cannot be parsed as a number, it defaults to 0.

§Arguments
  • node - A reference to a roxmltree::Node representing the <Slot> element.
§Returns

A Slot struct populated with the parsed values.

§Example
let doc = roxmltree::Document::parse(r#"<Slot id="3" name="ATL"/>"#).unwrap();
assert_eq!(doc.id, 3);
assert_eq!(doc.name, "ATL".to_string());
Source

fn parse_distance(node: &Node<'_, '_>) -> Distance

Parses a <Distance> XML node and converts it into a Distance struct.

This function reads the attributes of the given XML node and fills the corresponding fields in Distance. If an attribute is missing or cannot be parsed as a number, it defaults to 0.

§Arguments
  • node - A reference to a roxmltree::Node representing the <Distance> element.
§Returns

A Distance struct populated with the parsed values.

§Example
let doc = roxmltree::Document::parse(r#"<Distance dist="15" team1="2" team2="5"/>"#).unwrap();
let node = doc.root_element();
let distance = parse_distance(&node);
assert_eq!(distance.dist, 15);
assert_eq!(distance.team1, 2);
assert_eq!(distance.team2, 5);
Source

fn parse_capacity(node: &Node<'_, '_>) -> CapacityConstraints

Parses a <CapacityConstraints> XML node and converts it into a CapacityConstraints struct.

This function reads the attributes of the given XML node and fills the corresponding fields in CapacityConstraints. If an attribute is missing or cannot be parsed, numeric fields default to 0.

§Arguments
  • node - A reference to a roxmltree::Node representing the <CapacityConstraints> element.
§Returns

A CapacityConstraints struct populated with the parsed values.

§Example
let doc = roxmltree::Document::parse(r#"<Capacity intp="2" max="5" min="1" mode1="H" mode2="A" penalty="10" teamGroups1="3" teamGroups2="2" type="hard"/>"#).unwrap();
let node = doc.root_element();
let capacity = parse_capacity(&node);
assert_eq!(capacity.c_intp, 2);
assert_eq!(capacity.c_type, "hard".to_string());
Source

fn parse_separation(node: &Node<'_, '_>) -> SeparationConstraints

Parses a <SeparationConstraint> XML node and converts it into a SeparationConstraints struct.

This function reads the attributes of the given XML node and fills the corresponding fields in SeparationConstraints. If an attribute is missing or cannot be parsed as a number, it defaults to 0.

§Arguments
  • node - A reference to a roxmltree::Node representing the <SeparationConstraint> element.
§Returns

A SeparationConstraints struct populated with the parsed values.

§Example
let doc = roxmltree::Document::parse(r#"<Separation max="3" min="1" penalty="5" teamGroups="2" type="soft"/>"#).unwrap();
let node = doc.root_element();
let separation = parse_separation(&node);
assert_eq!(separation.c_max, 3);
assert_eq!(separation.c_type, "soft".to_string());

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

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

§

fn vzip(self) -> V