accessibility_rs/engine/rules/wcag_base.rs
1/// the success criteria to use
2#[derive(Debug)]
3pub enum IssueType {
4 /// a hard error that should be fixed
5 Error,
6 /// a warning that may be an issue
7 Warning,
8 /// a generic notice to help accessibility needs
9 Notice,
10}
11
12impl IssueType {
13 /// get rule id to string
14 pub fn as_str(&self) -> &'static str {
15 match self {
16 IssueType::Error => "error",
17 IssueType::Warning => "warning",
18 IssueType::Notice => "notice",
19 }
20 }
21}
22
23/// wcag principle to follow
24#[derive(Debug)]
25pub enum Principle {
26 /// Provide text alternatives for any non-text content so that it can be changed into other forms people need, such as large print, braille, speech, symbols or simpler language.
27 Perceivable,
28 /// Make all functionality available from a keyboard.
29 Operable,
30 /// Make text content readable and understandable.
31 Understandable,
32 /// Maximize compatibility with current and future user agents, including assistive technologies.
33 Robust,
34}
35
36impl Principle {
37 /// the principle to string code
38 pub fn as_str(&self) -> &'static str {
39 match self {
40 Principle::Perceivable => "Principle1",
41 Principle::Operable => "Principle2",
42 Principle::Understandable => "Principle3",
43 Principle::Robust => "Principle4",
44 }
45 }
46 /// the principle index
47 pub fn as_index(&self) -> &'static str {
48 match self {
49 Principle::Perceivable => "1",
50 Principle::Operable => "2",
51 Principle::Understandable => "3",
52 Principle::Robust => "4",
53 }
54 }
55}
56
57/// wcag principle to follow
58#[derive(Debug)]
59pub enum Guideline {
60 /// Provide text alternatives for any non-text content so that it can be changed into other forms people need.
61 TextAlternatives,
62 /// Create content that can be presented in different ways (for example simpler layout) without losing information or structure.
63 Adaptable,
64 /// Make it easier for users to see and hear content including separating foreground from background.
65 Distinguishable,
66 /// Provide users enough time to read and use content.
67 EnoughTime,
68 /// Do not design content in a way that is known to cause seizures.
69 Seizures,
70 /// Provide ways to help users navigate, find content, and determine where they are.
71 Navigable,
72 /// Make text content readable and understandable.
73 Readable,
74 /// Make Web pages appear and operate in predictable ways.
75 Predictable,
76 /// Maximize compatibility with current and future user agents, including assistive technologies.
77 Compatible,
78}
79
80impl Guideline {
81 /// the guideline to string code
82 pub fn as_str(&self) -> &'static str {
83 match self {
84 Guideline::TextAlternatives => "Guideline1_1",
85 Guideline::Adaptable => "Guideline1_3",
86 Guideline::Distinguishable => "Guideline1_4",
87 Guideline::EnoughTime => "Guideline2_2",
88 Guideline::Seizures => "Guideline2_3",
89 Guideline::Navigable => "Guideline2_4",
90 Guideline::Readable => "Guideline3_1",
91 Guideline::Predictable => "Guideline3_2",
92 Guideline::Compatible => "Guideline4_1",
93 }
94 }
95 /// the principle index
96 pub fn as_index(&self) -> &'static str {
97 let s = self.as_str();
98 &s[9..s.len()]
99 }
100}