pub trait Client {
// Required methods
fn years(&self) -> Vec<Year>;
fn days(&self, year: Year) -> Option<Vec<Day>>;
fn get_input(&self, day: Day, year: Year) -> Result<String, ClientError>;
fn submit_answer(
&mut self,
answer: Answer,
part: Part,
day: Day,
year: Year,
) -> Result<CheckResult, ClientError>;
fn get_puzzle(&self, day: Day, year: Year) -> Result<Puzzle, ClientError>;
}Expand description
Primary abstraction for interacting with the Advent of Code service.
This trait provides methods to fetch puzzle inputs, submit answers, and retrieve cached puzzle data. Implementors of this trait must cache inputs and answers to minimize requests to the AoC service.
§Caching Behavior
- Inputs are cached with encryption (configured at client creation).
get_input()returns cached data if possible. - Answers are cached unencrypted.
submit_answer()checks the cache first before submitting to the service. - Submission timeouts are persisted and enforced by the client. If a submission fails with a retry timeout, the client will refuse further submissions until the timeout expires.
§Timezone Handling
The client uses Eastern Time (UTC-5/-4) for determining puzzle availability, matching the Advent of Code event timezone. Internally, times are stored in UTC. Puzzle availability is based on the Eastern Time date/time.
§Submission Constraints
The Advent of Code service enforces rate limiting on answer submissions:
- You can submit one answer per puzzle part per minute.
- After submitting an incorrect answer, you must wait an increasing duration before the next attempt.
- After submitting a correct answer, that part is locked and cannot be resubmitted.
Required Methods§
Sourcefn years(&self) -> Vec<Year>
fn years(&self) -> Vec<Year>
Returns the list of available puzzle years starting at 2015. The current year is included when the current month is December.
Sourcefn days(&self, year: Year) -> Option<Vec<Day>>
fn days(&self, year: Year) -> Option<Vec<Day>>
Returns the list of available puzzle days for a given year. None is returned when year
is the current year, and the current month is not December.
Sourcefn get_input(&self, day: Day, year: Year) -> Result<String, ClientError>
fn get_input(&self, day: Day, year: Year) -> Result<String, ClientError>
Fetches the puzzle input for a given day and year. Cached inputs are returned without fetching from the service.
Sourcefn submit_answer(
&mut self,
answer: Answer,
part: Part,
day: Day,
year: Year,
) -> Result<CheckResult, ClientError>
fn submit_answer( &mut self, answer: Answer, part: Part, day: Day, year: Year, ) -> Result<CheckResult, ClientError>
Submits an answer for a puzzle part. Cached answers are returned immediately without submitting to the service.
Sourcefn get_puzzle(&self, day: Day, year: Year) -> Result<Puzzle, ClientError>
fn get_puzzle(&self, day: Day, year: Year) -> Result<Puzzle, ClientError>
Fetches the complete puzzle data (input and cached answers) for a given day and year.