Skip to main content

cp_cli_platform_project_euler/
lib.rs

1//! Bounded public Project Euler problem access
2
3mod client;
4mod error;
5
6pub use client::Client;
7pub use error::Error;
8
9/// The licence applied by Project Euler to archive and recent problem content
10pub const PROBLEM_CONTENT_LICENSE: &str = "CC BY-NC-SA 4.0";
11/// The official Project Euler licence page
12pub const PROBLEM_CONTENT_LICENSE_URL: &str = "https://creativecommons.org/licenses/by-nc-sa/4.0/";
13/// Required source credit for displayed Project Euler problem content
14pub const PROBLEM_CONTENT_ATTRIBUTION: &str = "Problem content from Project Euler";
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct Difficulty {
18    pub level: u8,
19    pub percentage: u8,
20}
21
22#[derive(Debug, PartialEq, Eq)]
23pub struct ProblemSummary {
24    pub number: u16,
25    pub title: Box<str>,
26    pub solved_count: Option<u32>,
27    pub published_at: Option<Box<str>>,
28    pub canonical_url: Box<str>,
29}
30
31#[derive(Debug, PartialEq, Eq)]
32pub struct ArchivePage {
33    pub page: u8,
34    pub problems: Vec<ProblemSummary>,
35}
36
37#[derive(Debug, PartialEq, Eq)]
38pub struct RecentProblems {
39    pub problems: Vec<ProblemSummary>,
40}
41
42/// Every public Project Euler problem listed by its compact catalogue endpoint
43#[derive(Debug, PartialEq, Eq)]
44pub struct ProblemCatalog {
45    pub problems: Vec<ProblemSummary>,
46}
47
48#[derive(Debug, PartialEq, Eq)]
49pub struct Problem {
50    pub summary: ProblemSummary,
51    pub difficulty: Option<Difficulty>,
52    /// Public HTML fragment from Project Euler's minimal problem endpoint
53    ///
54    /// Callers must treat this as untrusted HTML and sanitize it before rendering
55    pub statement_html: Box<str>,
56    pub attribution: &'static str,
57    pub license: &'static str,
58    pub license_url: &'static str,
59}
60
61#[cfg(test)]
62mod tests;