Struct scoreboard::ScoreBoard

source ·
pub struct ScoreBoard { /* private fields */ }
Expand description

Score board representation

Implementations§

source§

impl ScoreBoard

source

pub fn new() -> ScoreBoard

Returns a newly created, empty score board

source

pub fn start_game<T: ToString, U: ToString>( &mut self, home: T, away: U ) -> Result<(), String>

Starts a game between two teams, with initial score 0 - 0

Arguments
  • home - Name of the home team. Must be either a String or a type that is convertable to String
  • away - Name of the away team. Must be either a String or a type that is convertable to String
Errors
  • When the two provided names are the same
  • When any of the provided team is currently playing a match
Examples
let mut expected_result: Vec<String> = Vec::new();
expected_result.push(String::from("Japan 0 - Indonesia 0"));

let mut sb = scoreboard::ScoreBoard::new();
sb.start_game("Japan", "Indonesia");
let summary = sb.get_summary();
assert_eq!(summary, expected_result);
source

pub fn update_score<T: ToString, U: ToString>( &mut self, home: T, new_home_score: u8, away: U, new_away_score: u8 ) -> Result<(), String>

Updates a score of a running match with absolute values

Arguments
  • home - Name of the home team. Must be either a String or a type that is convertable to String
  • new_home_score - A new score to be set for the home team
  • away - Name of the away team. Must be either a String or a type that is convertable to String
  • new_away_score - A new score to be set for the away team
Errors
  • When there is no active match between the given teams
Examples
let mut expected_result: Vec<String> = Vec::new();
expected_result.push(String::from("Japan 2 - Indonesia 0"));

let mut sb = scoreboard::ScoreBoard::new();
sb.start_game("Japan", "Indonesia");
sb.update_score("Japan", 2, "Indonesia", 0);
let summary = sb.get_summary();
assert_eq!(summary, expected_result);
source

pub fn finish_game<T: ToString, U: ToString>( &mut self, home: T, away: U ) -> Result<(), String>

Finishes a match and removes it from the score board

Arguments
  • home - Name of the home team. Must be either a String or a type that is convertable to String
  • away - Name of the away team. Must be either a String or a type that is convertable to String
Errors
  • When there is no active match between the given teams
Examples
let mut expected_result: Vec<String> = Vec::new();

let mut sb = scoreboard::ScoreBoard::new();
sb.start_game("Japan", "Indonesia");
sb.update_score("Japan", 2, "Indonesia", 0);
sb.finish_game("Japan", "Indonesia");
let summary = sb.get_summary();
assert_eq!(summary, expected_result);
source

pub fn get_summary(&self) -> Vec<String>

Provides the current status of the scoreboard, with all current matches listed. The matches are ordered by total score (the highest coming first) and, in the case of the same score, by start time (the earliest match coming first)

Returns
  • A vector of strings, each string containing the home team, its score, the away team and its score
Examples
let mut expected_result: Vec<String> = Vec::new();
expected_result.push(String::from("Japan 0 - Indonesia 0"));

let mut sb = scoreboard::ScoreBoard::new();
sb.start_game("Japan", "Indonesia");
let summary = sb.get_summary();
assert_eq!(summary, expected_result);

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.