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?
76fn print_timezone_warnings(
77 cdr: &cdr::Versioned<'_>,
78 warnings: &warning::Report<timezone::WarningKind>,
79) {
80 if warnings.is_empty() {
81 return;
82 }
83
84 eprintln!("WARN: {} warnings from the timezone search", warnings.len());
85
86 for warning::ElementReport { element, warnings } in warnings.iter(cdr.as_element()) {
87 eprintln!(
88 "Warnings reported for `json::Element` at path: `{}`",
89 element.path()
90 );
91
92 for warning in warnings {
93 eprintln!(" * {warning}");
94 }
95
96 eprintln!();
97 }
98}
More examples
29fn print_lint_warnings(
30 tariff: &tariff::Versioned<'_>,
31 warnings: &warning::Report<lint::tariff::WarningKind>,
32) {
33 if warnings.is_empty() {
34 return;
35 }
36
37 eprintln!("WARN: {} warnings from the linting", warnings.len());
38
39 for warning::ElementReport { element, warnings } in warnings.iter(tariff.as_element()) {
40 eprintln!(
41 "Warnings reported for `json::Element` at path: `{}`",
42 element.path()
43 );
44
45 for warning in warnings {
46 eprintln!(" * {warning}");
47 }
48
49 eprintln!();
50 }
51}
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.