use *;
pub struct ParticipantsIter<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
filter: TournamentParticipantsFilter,
}
impl<'a> ParticipantsIter<'a> {
pub fn new(client: &'a Toornament, tournament_id: TournamentId) -> ParticipantsIter {
ParticipantsIter {
client,
tournament_id,
filter: TournamentParticipantsFilter::default(),
}
}
}
impl<'a> ParticipantsIter<'a> {
pub fn with_filter(mut self, filter: TournamentParticipantsFilter) -> Self {
self.filter = filter;
self
}
pub fn of_tournament(mut self, id: TournamentId) -> Self {
self.tournament_id = id;
self
}
}
impl<'a> ParticipantsIter<'a> {
pub fn with_id(self, id: ParticipantId) -> ParticipantIter<'a> {
ParticipantIter::new(self.client, self.tournament_id, id)
}
pub fn edit<F: 'static + FnMut(Participants) -> Participants>(
self,
editor: F,
) -> ParticipantsEditor<'a> {
ParticipantsEditor {
client: self.client,
tournament_id: self.tournament_id,
filter: self.filter,
editor: Box::new(editor),
}
}
pub fn create<F: 'static + FnMut() -> Participant>(self, creator: F) -> ParticipantCreator<'a> {
ParticipantCreator {
client: self.client,
tournament_id: self.tournament_id,
creator: Box::new(creator),
}
}
}
impl<'a> ParticipantsIter<'a> {
pub fn collect<T: From<Participants>>(self) -> Result<T> {
Ok(T::from(self.client.tournament_participants(
self.tournament_id,
self.filter,
)?))
}
}
pub struct ParticipantsEditor<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
filter: TournamentParticipantsFilter,
editor: Box<dyn FnMut(Participants) -> Participants>,
}
impl<'a> ParticipantsEditor<'a> {
pub fn update(mut self) -> Result<Participants> {
let original = self
.client
.tournament_participants(self.tournament_id.clone(), self.filter)?;
let edited = (self.editor)(original);
self.client
.update_tournament_participants(self.tournament_id, edited)
}
}
pub struct ParticipantIter<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
id: ParticipantId,
}
impl<'a> ParticipantIter<'a> {
pub fn new(
client: &'a Toornament,
tournament_id: TournamentId,
id: ParticipantId,
) -> ParticipantIter {
ParticipantIter {
client,
tournament_id,
id,
}
}
}
impl<'a> ParticipantIter<'a> {
pub fn edit<F: 'static + FnMut(Participant) -> Participant>(
self,
editor: F,
) -> ParticipantEditor<'a> {
ParticipantEditor {
client: self.client,
tournament_id: self.tournament_id,
id: self.id,
editor: Box::new(editor),
}
}
}
impl<'a> ParticipantIter<'a> {
pub fn collect<T: From<Participant>>(self) -> Result<T> {
Ok(T::from(
self.client
.tournament_participant(self.tournament_id, self.id)?,
))
}
pub fn delete(self) -> Result<()> {
self.client
.delete_tournament_participant(self.tournament_id, self.id)
}
pub fn update(self, participant: Participant) -> Result<Participant> {
self.client
.update_tournament_participant(self.tournament_id, self.id, participant)
}
}
pub struct ParticipantCreator<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
creator: Box<dyn FnMut() -> Participant>,
}
impl<'a> ParticipantCreator<'a> {
pub fn update(mut self) -> Result<Participant> {
self.client
.create_tournament_participant(self.tournament_id, (self.creator)())
}
}
pub struct ParticipantEditor<'a> {
client: &'a Toornament,
tournament_id: TournamentId,
id: ParticipantId,
editor: Box<dyn FnMut(Participant) -> Participant>,
}
impl<'a> ParticipantEditor<'a> {
pub fn update(mut self) -> Result<Participant> {
let original = self
.client
.tournament_participant(self.tournament_id.clone(), self.id.clone())?;
let edited = (self.editor)(original);
self.client
.update_tournament_participant(self.tournament_id, self.id, edited)
}
}