@@ -2,31 +2,69 @@ use serde::{ser::SerializeStruct, Serialize};
2
2
3
3
use crate :: { Check , CheckId , Status , StatusCode } ;
4
4
5
+ #[ derive( Debug , Clone , Serialize ) ]
6
+ pub enum FixResult {
7
+ /// A fix was available, but not requested
8
+ Available ,
9
+ /// A fix was requested, but no fix was available
10
+ Unfixable ,
11
+ /// A fix was applied
12
+ Fixed ,
13
+ /// The fix failed, for some reason
14
+ FixError ( String ) ,
15
+ }
16
+
5
17
#[ derive( Debug , Clone ) ]
18
+ /// The result of a check on one or more font files.
19
+ ///
20
+ /// This struct is used to store the results of a check on one or more font files.
21
+ /// A check may return multiple sub-results, as the test checks different aspects
22
+ /// of the font file(s). Additionally, fontspector can be used to fix problems
23
+ /// found in the font, either at the source or by applying a hotfix. The results
24
+ /// of these fixes are stored in the `hotfix_result` and `sourcefix_result` fields.
6
25
pub struct CheckResult {
26
+ /// The ID of the check
7
27
pub check_id : CheckId ,
28
+ /// A simple title for the check
8
29
pub check_name : String ,
30
+ /// The rationale for the check
9
31
pub check_rationale : String ,
32
+ /// The file which was checked; if None, the check was run on all files
10
33
pub filename : Option < String > ,
34
+ /// The section of the profile this check belongs to
11
35
pub section : String ,
36
+ /// The individual results of the check
12
37
pub subresults : Vec < Status > ,
38
+ /// If hotfixing was attempted, the result of the hotfix
39
+ pub hotfix_result : Option < FixResult > ,
40
+ /// If source fixing was attempted, the result of the source fix
41
+ pub sourcefix_result : Option < FixResult > ,
13
42
}
14
43
15
44
impl Serialize for CheckResult {
16
45
fn serialize < S : serde:: Serializer > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > {
17
- let mut s = serializer. serialize_struct ( "CheckResult" , 7 ) ?;
46
+ let fields =
47
+ 7 + self . hotfix_result . is_some ( ) as usize + self . sourcefix_result . is_some ( ) as usize ;
48
+ let mut s = serializer. serialize_struct ( "CheckResult" , fields) ?;
18
49
s. serialize_field ( "check_id" , & self . check_id ) ?;
19
50
s. serialize_field ( "check_name" , & self . check_name ) ?;
20
51
s. serialize_field ( "check_rationale" , & self . check_rationale ) ?;
21
52
s. serialize_field ( "filename" , & self . filename ) ?;
22
53
s. serialize_field ( "section" , & self . section ) ?;
23
54
s. serialize_field ( "subresults" , & self . subresults ) ?;
24
55
s. serialize_field ( "worst_status" , & self . worst_status ( ) ) ?;
56
+ if let Some ( hotfix_result) = & self . hotfix_result {
57
+ s. serialize_field ( "hotfix_result" , hotfix_result) ?;
58
+ }
59
+ if let Some ( sourcefix_result) = & self . sourcefix_result {
60
+ s. serialize_field ( "sourcefix_result" , sourcefix_result) ?;
61
+ }
25
62
s. end ( )
26
63
}
27
64
}
28
65
29
66
impl CheckResult {
67
+ /// Create a new CheckResult
30
68
pub fn new (
31
69
check : & Check ,
32
70
filename : Option < & str > ,
@@ -40,9 +78,12 @@ impl CheckResult {
40
78
filename : filename. map ( |x| x. to_string ( ) ) ,
41
79
section : section. to_string ( ) ,
42
80
subresults,
81
+ hotfix_result : None ,
82
+ sourcefix_result : None ,
43
83
}
44
84
}
45
85
86
+ /// Get the worst status of all subresults
46
87
pub fn worst_status ( & self ) -> StatusCode {
47
88
self . subresults
48
89
. iter ( )
@@ -51,6 +92,7 @@ impl CheckResult {
51
92
. unwrap_or ( StatusCode :: Pass )
52
93
}
53
94
95
+ /// If this check returned some kind of Rust error that we handled
54
96
pub fn is_error ( & self ) -> bool {
55
97
self . worst_status ( ) == StatusCode :: Error
56
98
}
0 commit comments