pub struct Element<'buf> { /* private fields */ }Expand description
Implementations§
Source§impl<'buf> Element<'buf>
impl<'buf> Element<'buf>
Sourcepub fn path(&self) -> PathRef<'buf>
pub fn path(&self) -> PathRef<'buf>
Return the Path to this Element.
Examples found in repository?
75fn print_timezone_warnings(
76 cdr: &cdr::Versioned<'_>,
77 warnings: &warning::Report<timezone::WarningKind>,
78) {
79 if warnings.is_empty() {
80 return;
81 }
82
83 eprintln!("WARN: {} warnings from the timezone search", warnings.len());
84
85 for warning::ElementReport { element, warnings } in warnings.iter(cdr.as_element()) {
86 eprintln!(
87 "Warnings reported for `json::Element` at path: `{}`",
88 element.path()
89 );
90
91 for warning in warnings {
92 eprintln!(" * {warning}");
93 }
94
95 eprintln!();
96 }
97}More examples
32fn print_lint_warnings(
33 tariff: &tariff::Versioned<'_>,
34 warnings: &warning::Report<lint::tariff::WarningKind>,
35) {
36 if warnings.is_empty() {
37 return;
38 }
39
40 eprintln!("WARN: {} warnings from the linting", warnings.len());
41
42 for warning::ElementReport { element, warnings } in warnings.iter(tariff.as_element()) {
43 eprintln!(
44 "Warnings reported for `json::Element` at path: `{}`",
45 element.path()
46 );
47
48 for warning in warnings {
49 eprintln!(" * {warning}");
50 }
51
52 eprintln!();
53 }
54}Sourcepub fn source_json(&self, source_json: &'buf str) -> SourceStr<'buf>
pub fn source_json(&self, source_json: &'buf str) -> SourceStr<'buf>
Return the source JSON &str of the entire Object field if the Element is an Object.
Otherwise return the span of the [Value].
In the case of an array like ["one", "two"], calling this method on the second Element
will return "two".
In the case of an object like {"one": 1, "two": 2}, calling this method on the second
Element will return "\"two\": 2".
§Panics
If a source JSON is used that this Element didn’t not originate from there is a chance
that this function will panic.
Sourcepub fn source_json_value(&self, source_json: &'buf str) -> &'buf str
pub fn source_json_value(&self, source_json: &'buf str) -> &'buf str
Return the source JSON &str for the [Value].
In the case of an array like ["one", "two"], calling this method on the second Element
will return "two".
In the case of an object like {"one": 1, "two": 2}, calling this method on the second
Element will return "2".
§Panics
If a source JSON is used that this Element didn’t not originate from there is a chance
that this function will panic.