use *;
pub struct GamesIter<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
match_id: MatchId,
with_stats: bool,
}
impl<'a> GamesIter<'a> {
pub fn new(
client: &'a Toornament,
tournament_id: TournamentId,
match_id: MatchId,
) -> GamesIter<'a> {
GamesIter {
client,
tournament_id,
match_id,
with_stats: false,
}
}
}
impl<'a> GamesIter<'a> {
pub fn with_stats(mut self, with_stats: bool) -> Self {
self.with_stats = with_stats;
self
}
}
impl<'a> GamesIter<'a> {
pub fn with_number(self, number: GameNumber) -> GameIter<'a> {
GameIter {
client: self.client,
tournament_id: self.tournament_id,
match_id: self.match_id,
with_stats: self.with_stats,
number,
}
}
}
impl<'a> GamesIter<'a> {
pub fn collect<T: From<Games>>(self) -> Result<T> {
Ok(T::from(self.client.match_games(
self.tournament_id,
self.match_id,
self.with_stats,
)?))
}
}
pub struct GameIter<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
match_id: MatchId,
with_stats: bool,
number: GameNumber,
}
impl<'a> GameIter<'a> {
pub fn edit<F: 'static + FnMut(Game) -> Game>(self, editor: F) -> GameEditor<'a> {
GameEditor {
client: self.client,
tournament_id: self.tournament_id,
match_id: self.match_id,
with_stats: self.with_stats,
number: self.number,
editor: Box::new(editor),
}
}
pub fn result(self) -> GameResultIter<'a> {
GameResultIter {
client: self.client,
tournament_id: self.tournament_id,
match_id: self.match_id,
number: self.number,
}
}
}
impl<'a> GameIter<'a> {
pub fn collect<T: From<Game>>(self) -> Result<T> {
Ok(T::from(self.client.match_game(
self.tournament_id,
self.match_id,
self.number,
self.with_stats,
)?))
}
}
pub struct GameEditor<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
match_id: MatchId,
with_stats: bool,
number: GameNumber,
editor: Box<dyn FnMut(Game) -> Game>,
}
impl<'a> GameEditor<'a> {
pub fn update(mut self) -> Result<Game> {
let original = self.client.match_game(
self.tournament_id.clone(),
self.match_id.clone(),
self.number,
self.with_stats,
)?;
self.client.update_match_game(
self.tournament_id,
self.match_id,
self.number,
(self.editor)(original),
)
}
}
pub struct GameResultIter<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
match_id: MatchId,
number: GameNumber,
}
impl<'a> GameResultIter<'a> {
pub fn edit<F: 'static + FnMut(MatchResult) -> MatchResult>(
self,
editor: F,
) -> GameResultEditor<'a> {
GameResultEditor {
client: self.client,
tournament_id: self.tournament_id,
match_id: self.match_id,
number: self.number,
editor: Box::new(editor),
}
}
}
impl<'a> GameResultIter<'a> {
pub fn collect<T: From<MatchResult>>(self) -> Result<T> {
Ok(T::from(self.client.match_game_result(
self.tournament_id,
self.match_id,
self.number,
)?))
}
}
pub struct GameResultEditor<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
match_id: MatchId,
number: GameNumber,
editor: Box<dyn FnMut(MatchResult) -> MatchResult>,
}
impl<'a> GameResultEditor<'a> {
pub fn update(mut self) -> Result<MatchResult> {
let original = self.client.match_game_result(
self.tournament_id.clone(),
self.match_id.clone(),
self.number,
)?;
self.client.update_match_game_result(
self.tournament_id,
self.match_id,
self.number,
(self.editor)(original),
true,
)
}
}