77use std:: sync:: Arc ;
88
99use orx_concurrent_vec:: ConcurrentVec ;
10- use serde:: Serialize ;
1110
1211/// The kind of problem being reported
13- #[ derive( Debug , Serialize , Clone ) ]
14- #[ serde( tag = "type" ) ]
15- enum Kind {
12+ #[ derive( Debug , Clone ) ]
13+ pub enum Kind {
1614 /// Expected and Required field is missing
1715 MissingField {
1816 /// Name of the missing field
@@ -73,21 +71,33 @@ enum Kind {
7371}
7472
7573/// Problem Report Entry
76- #[ derive( Debug , Serialize , Clone ) ]
77- struct Entry {
74+ #[ derive( Debug , Clone ) ]
75+ pub struct Entry {
7876 /// The kind of problem we are recording.
7977 kind : Kind ,
8078 /// Any extra context information we want to add.
8179 context : String ,
8280}
8381
82+ impl Entry {
83+ /// Gets the kind of the problem of the entry.
84+ pub fn kind ( & self ) -> & Kind {
85+ & self . kind
86+ }
87+
88+ /// Gets extra information of the entry.
89+ pub fn context ( & self ) -> & String {
90+ & self . context
91+ }
92+ }
93+
8494/// The Problem Report list
85- #[ derive( Debug , Clone , Serialize ) ]
86- struct Report ( ConcurrentVec < Entry > ) ;
95+ #[ derive( Debug , Clone ) ]
96+ pub struct Report ( ConcurrentVec < Entry > ) ;
8797
8898/// An inner state of the report.
89- #[ derive( Debug , Serialize ) ]
90- struct State {
99+ #[ derive( Debug ) ]
100+ pub struct State {
91101 /// What context does the whole report have
92102 context : String ,
93103 /// The report itself
@@ -97,7 +107,7 @@ struct State {
97107/// Problem Report.
98108///
99109/// This structure allows making a cheap copies that share the same state.
100- #[ derive( Debug , Clone , Serialize ) ]
110+ #[ derive( Debug , Clone ) ]
101111pub struct ProblemReport ( Arc < State > ) ;
102112
103113impl ProblemReport {
@@ -147,6 +157,16 @@ impl ProblemReport {
147157 !self . 0 . report . 0 . is_empty ( )
148158 }
149159
160+ /// Gets entries from the report.
161+ pub fn entries ( & self ) -> & ConcurrentVec < Entry > {
162+ & self . 0 . report . 0
163+ }
164+
165+ /// Gets context from the report.
166+ pub fn context ( & self ) -> & String {
167+ & self . 0 . context
168+ }
169+
150170 /// Add an entry to the report
151171 fn add_entry (
152172 & self ,
@@ -500,14 +520,4 @@ mod tests {
500520 // The original report must have the same (problematic) state.
501521 assert ! ( original. is_problematic( ) ) ;
502522 }
503-
504- #[ test]
505- fn serialize ( ) {
506- let report = ProblemReport :: new ( "top level context" ) ;
507- report. invalid_value ( "field name" , "found" , "constraint" , "context" ) ;
508-
509- let serialized = serde_json:: to_string ( & report) . unwrap ( ) ;
510- let expected = r#"{"context":"top level context","report":[{"kind":{"type":"InvalidValue","field":"field name","value":"found","constraint":"constraint"},"context":"context"}]}"# ;
511- assert_eq ! ( serialized, expected) ;
512- }
513523}
0 commit comments