pub struct Set<W: Warning>(/* private fields */);Implementations§
Source§impl Set<Warning>
impl Set<Warning>
Sourcepub fn unexpected_fields(&self) -> PathSet<'_>
pub fn unexpected_fields(&self) -> PathSet<'_>
Collect the field paths of all Warning::UnexpectedField warnings into a set of json::Paths.
Sourcepub fn missing_fields(&self) -> PathSet<'_>
pub fn missing_fields(&self) -> PathSet<'_>
Collect the field paths of all Warning::MissingField warnings into a set of json::Paths.
Sourcepub fn remove_unexpected_fields(&mut self)
pub fn remove_unexpected_fields(&mut self)
Remove all Warning::UnexpectedField warnings from the set.
Sourcepub fn remove_missing_fields(&mut self)
pub fn remove_missing_fields(&mut self)
Remove all Warning::MissingField warnings from the set.
Sourcepub fn remove_type_mismatches(&mut self)
pub fn remove_type_mismatches(&mut self)
Remove all Warning::TypeMismatch warnings from the set.
Sourcepub fn remove_null_fields(&mut self)
pub fn remove_null_fields(&mut self)
Remove all Warning::NullField warnings from the set.
Sourcepub fn remove_cardinalities(&mut self)
pub fn remove_cardinalities(&mut self)
Remove all Warning::Cardinality warnings from the set.
Sourcepub fn remove_string_too_longs(&mut self)
pub fn remove_string_too_longs(&mut self)
Remove all Warning::StringTooLong warnings from the set.
Source§impl<W: Warning> Set<W>
impl<W: Warning> Set<W>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true if the Warning set is empty.
Examples found in repository?
More examples
22fn print_schema_warnings(warnings: &warning::Set<schema::Warning>) {
23 if warnings.is_empty() {
24 return;
25 }
26
27 eprintln!(
28 "WARN: {} schema warnings from the tariff:\n {}",
29 warnings.len_warnings(),
30 warning::SetWriter::new(warnings)
31 );
32}
33
34/// Print `lint::tariff::Warning`s to `stderr`.
35fn print_lint_warnings(warnings: &warning::Set<lint::tariff::Warning>) {
36 if warnings.is_empty() {
37 return;
38 }
39
40 eprintln!(
41 "WARN: {} warnings from the linting:\n {}",
42 warnings.len_warnings(),
43 warning::SetWriter::new(warnings)
44 );
45}7fn main() {
8 const CDR_JSON: &str = include_str!("data/cdr_time_and_parking_time.json");
9
10 // If you know the version of a CDR you can parse it into a `json::Document` and validate it
11 // against the schema for that version.
12 let doc = json::parse_object(CDR_JSON).expect("unable to parse CDR");
13 let (cdr, warnings) = cdr::build(doc, Version::V211).into_parts();
14
15 if !warnings.is_empty() {
16 eprintln!("The CDR has `{}` schema warnings.", warnings.len_warnings());
17 }
18
19 let report = match cdr::price(&cdr, price::TariffSource::UseCdr, Tz::Europe__Amsterdam) {
20 Ok(r) => r,
21 Err(set) => {
22 let (error, warnings) = set.into_parts();
23 print_pricing_error(&error);
24 print_pricing_warnings(&warnings);
25 return;
26 }
27 };
28
29 let (report, warnings) = report.into_parts();
30 print_pricing_warnings(&warnings);
31
32 // The various fields of the `price::Report` can be examined or converted to JSON.
33 let price::Report {
34 periods: _,
35 tariff_used: _,
36 tariff_reports: _,
37 timezone: _,
38 billed_energy: _,
39 billed_idle_time: _,
40 total_charging_time: _,
41 billed_charging_time: _,
42 total_cost: _,
43 total_fixed_cost: _,
44 total_time: _,
45 total_charging_time_cost: _,
46 total_energy: _,
47 total_energy_cost: _,
48 total_idle_time: _,
49 total_idle_cost: _,
50 } = report;
51}
52
53/// Print `price::Warning` that halted the example to `stderr`.
54fn print_pricing_error(error: &warning::Error<price::Warning>) {
55 eprintln!(
56 "ERR: Unable to price CDR due to error at path `{}`: {}",
57 error.element().path,
58 error.warning()
59 );
60}
61
62/// Print `price::Warning`s to `stderr`.
63fn print_pricing_warnings(warnings: &warning::Set<price::Warning>) {
64 if warnings.is_empty() {
65 return;
66 }
67
68 eprintln!(
69 "WARN: {} warnings from the pricing:\n {}",
70 warnings.len_warnings(),
71 warning::SetWriter::new(warnings)
72 );
73}6fn main() {
7 const CDR_JSON: &str = include_str!("data/cdr_time_and_parking_time.json");
8
9 // First the raw JSON is parsed into a `json::Document` and the OCPI version of the CDR is
10 // guessed. The `guess::CdrVersion` returned from calling `cdr::infer_version` is either certain
11 // or uncertain about the version of the contained `cdr::Versioned` object.
12 let cdr = json::parse_object(CDR_JSON).expect("Unable to parse CDR JSON");
13 let cdr = cdr::infer_version(cdr);
14
15 // The guessed Version can be either certain or uncertain.
16 // If the version is uncertain then fallback to presuming the CDR is v211.
17 let cdr = cdr.certain_or(Version::V211);
18 let cdr = cdr::build_versioned(cdr).ignore_warnings();
19
20 // The timezone can be inferred or found in the CDR, but a versioned CDR is required.
21 let timezone = match timezone::find_or_infer(&cdr) {
22 Ok(tz) => tz,
23 Err(err_set) => {
24 let (error, warnings) = err_set.into_parts();
25 eprintln!("Unable to infer timezone");
26 print_timezone_error(&error);
27 print_timezone_warnings(&warnings);
28 return;
29 }
30 };
31 let (timezone_source, warnings) = timezone.into_parts();
32
33 if !warnings.is_empty() {
34 print_timezone_warnings(&warnings);
35 }
36
37 // We don't care whether the timezone was found or inferred.
38 let timezone = timezone_source.into_timezone();
39
40 let report = match cdr::price(&cdr, price::TariffSource::UseCdr, timezone) {
41 Ok(r) => r,
42 Err(set) => {
43 let (error, warnings) = set.into_parts();
44 print_pricing_error(&error);
45 print_pricing_warnings(&warnings);
46 return;
47 }
48 };
49
50 let (report, warnings) = report.into_parts();
51
52 print_pricing_warnings(&warnings);
53
54 // The various fields of the `price::Report` can be examined or converted to JSON.
55 let price::Report {
56 periods: _,
57 tariff_used: _,
58 tariff_reports: _,
59 timezone: _,
60 billed_energy: _,
61 billed_idle_time: _,
62 total_charging_time: _,
63 billed_charging_time: _,
64 total_cost: _,
65 total_fixed_cost: _,
66 total_time: _,
67 total_charging_time_cost: _,
68 total_energy: _,
69 total_energy_cost: _,
70 total_idle_time: _,
71 total_idle_cost: _,
72 } = report;
73}
74
75/// Print the `timezone::Warning` that halted the example to `stderr`.
76fn print_timezone_error(error: &warning::Error<timezone::Warning>) {
77 eprintln!(
78 "ERR: Unable to find timezone due to error at path `{}`: {}",
79 error.element().path,
80 error.warning()
81 );
82}
83
84/// Print the `timezone::Warning`s to `stderr`.
85fn print_timezone_warnings(warnings: &warning::Set<timezone::Warning>) {
86 if warnings.is_empty() {
87 return;
88 }
89
90 eprintln!(
91 "WARN: {} warnings from the timezone search",
92 warnings.len_warnings()
93 );
94
95 eprintln!(
96 "WARN: {} warnings from the timezone search:\n {}",
97 warnings.len_warnings(),
98 warning::SetWriter::new(warnings)
99 );
100}
101
102/// Print the `price::Warning` that halted the process to `stderr`.
103fn print_pricing_error(error: &warning::Error<price::Warning>) {
104 eprintln!(
105 "ERR: Unable to price CDR due to error at path `{}`: {}",
106 error.element().path,
107 error.warning()
108 );
109}
110
111/// Print the `price::Warning`s to `stderr`.
112fn print_pricing_warnings(warnings: &warning::Set<price::Warning>) {
113 if warnings.is_empty() {
114 return;
115 }
116
117 eprintln!(
118 "WARN: {} warnings from the linting:\n {}",
119 warnings.len_warnings(),
120 warning::SetWriter::new(warnings)
121 );
122}Sourcepub fn len_elements(&self) -> usize
pub fn len_elements(&self) -> usize
Sourcepub fn len_warnings(&self) -> usize
pub fn len_warnings(&self) -> usize
Examples found in repository?
More examples
22fn print_schema_warnings(warnings: &warning::Set<schema::Warning>) {
23 if warnings.is_empty() {
24 return;
25 }
26
27 eprintln!(
28 "WARN: {} schema warnings from the tariff:\n {}",
29 warnings.len_warnings(),
30 warning::SetWriter::new(warnings)
31 );
32}
33
34/// Print `lint::tariff::Warning`s to `stderr`.
35fn print_lint_warnings(warnings: &warning::Set<lint::tariff::Warning>) {
36 if warnings.is_empty() {
37 return;
38 }
39
40 eprintln!(
41 "WARN: {} warnings from the linting:\n {}",
42 warnings.len_warnings(),
43 warning::SetWriter::new(warnings)
44 );
45}85fn print_timezone_warnings(warnings: &warning::Set<timezone::Warning>) {
86 if warnings.is_empty() {
87 return;
88 }
89
90 eprintln!(
91 "WARN: {} warnings from the timezone search",
92 warnings.len_warnings()
93 );
94
95 eprintln!(
96 "WARN: {} warnings from the timezone search:\n {}",
97 warnings.len_warnings(),
98 warning::SetWriter::new(warnings)
99 );
100}
101
102/// Print the `price::Warning` that halted the process to `stderr`.
103fn print_pricing_error(error: &warning::Error<price::Warning>) {
104 eprintln!(
105 "ERR: Unable to price CDR due to error at path `{}`: {}",
106 error.element().path,
107 error.warning()
108 );
109}
110
111/// Print the `price::Warning`s to `stderr`.
112fn print_pricing_warnings(warnings: &warning::Set<price::Warning>) {
113 if warnings.is_empty() {
114 return;
115 }
116
117 eprintln!(
118 "WARN: {} warnings from the linting:\n {}",
119 warnings.len_warnings(),
120 warning::SetWriter::new(warnings)
121 );
122}7fn main() {
8 const CDR_JSON: &str = include_str!("data/cdr_time_and_parking_time.json");
9
10 // If you know the version of a CDR you can parse it into a `json::Document` and validate it
11 // against the schema for that version.
12 let doc = json::parse_object(CDR_JSON).expect("unable to parse CDR");
13 let (cdr, warnings) = cdr::build(doc, Version::V211).into_parts();
14
15 if !warnings.is_empty() {
16 eprintln!("The CDR has `{}` schema warnings.", warnings.len_warnings());
17 }
18
19 let report = match cdr::price(&cdr, price::TariffSource::UseCdr, Tz::Europe__Amsterdam) {
20 Ok(r) => r,
21 Err(set) => {
22 let (error, warnings) = set.into_parts();
23 print_pricing_error(&error);
24 print_pricing_warnings(&warnings);
25 return;
26 }
27 };
28
29 let (report, warnings) = report.into_parts();
30 print_pricing_warnings(&warnings);
31
32 // The various fields of the `price::Report` can be examined or converted to JSON.
33 let price::Report {
34 periods: _,
35 tariff_used: _,
36 tariff_reports: _,
37 timezone: _,
38 billed_energy: _,
39 billed_idle_time: _,
40 total_charging_time: _,
41 billed_charging_time: _,
42 total_cost: _,
43 total_fixed_cost: _,
44 total_time: _,
45 total_charging_time_cost: _,
46 total_energy: _,
47 total_energy_cost: _,
48 total_idle_time: _,
49 total_idle_cost: _,
50 } = report;
51}
52
53/// Print `price::Warning` that halted the example to `stderr`.
54fn print_pricing_error(error: &warning::Error<price::Warning>) {
55 eprintln!(
56 "ERR: Unable to price CDR due to error at path `{}`: {}",
57 error.element().path,
58 error.warning()
59 );
60}
61
62/// Print `price::Warning`s to `stderr`.
63fn print_pricing_warnings(warnings: &warning::Set<price::Warning>) {
64 if warnings.is_empty() {
65 return;
66 }
67
68 eprintln!(
69 "WARN: {} warnings from the pricing:\n {}",
70 warnings.len_warnings(),
71 warning::SetWriter::new(warnings)
72 );
73}Sourcepub fn id_path_map(&self, config: Limit) -> IdPathMap<'_>
pub fn id_path_map(&self, config: Limit) -> IdPathMap<'_>
Return a collection of Ids mapped to the paths they occurred at.
Sourcepub fn msg_path_map(&self, config: Limit) -> MsgPathMap<'_>
pub fn msg_path_map(&self, config: Limit) -> MsgPathMap<'_>
Return a collection of warning messages mapped to the paths they occurred at.
Sourcepub fn path_map(&self) -> BTreeMap<&str, Vec<&W>>
pub fn path_map(&self) -> BTreeMap<&str, Vec<&W>>
Return a map of json::Element paths to a list of Warning.
This is designed to be used to print out maps of warnings associated with elements.
You can use the debug alternate format {:#?} to print the map ‘pretty’ over multiple lines
with indentation.
Sourcepub fn into_path_map(self) -> BTreeMap<Path, Vec<W>>
pub fn into_path_map(self) -> BTreeMap<Path, Vec<W>>
Consume the Set and return a map of json::Element paths to a list of Warnings.
This is designed to be used to print out maps of warnings associated with elements.
Sourcepub fn path_id_map(&self) -> BTreeMap<&str, Vec<Id>>
pub fn path_id_map(&self) -> BTreeMap<&str, Vec<Id>>
Return a map of json::Element paths to a list of Warning ids as Strings.
This is designed to be used to print out maps of warnings associated with elements.
You can use the debug alternate format {:#?} to print the map ‘pretty’ over multiple lines
with indentation.
Note: This representation is also valid JSON and can be copied directly to a test expectation file.
Sourcepub fn path_msg_map(&self) -> BTreeMap<&str, Vec<String>>
pub fn path_msg_map(&self) -> BTreeMap<&str, Vec<String>>
Return a map of json::Element paths to a list of Warning messages as Strings.
This is designed to be used to print out maps of warnings associated with elements.
You can use the debug alternate format {:#?} to print the map ‘pretty’ over multiple lines
with indentation.