pub struct Keys(/* private fields */);
Expand description
A span consisting of consecutive string keys.
Implementations§
Source§impl Keys
impl Keys
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a new empty instance with a capacity.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut String>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut String>
Mutable Iterator over the keys.
Sourcepub fn dotted(&self) -> String
pub fn dotted(&self) -> String
Returns the keys joined by dots.
Examples found in repository?
examples/schemars_json.rs (line 67)
10fn main() {
11 let schema_value = json! {
12 {
13 "$schema": "http://json-schema.org/draft-07/schema#",
14 "title": "SomeStruct",
15 "type": "object",
16 "required": [
17 "some_inner",
18 "some_int"
19 ],
20 "additionalProperties": false,
21 "properties": {
22 "some_inner": {
23 "type": "object",
24 "required": [
25 "inner_values",
26 "inner_value"
27 ],
28 "properties": {
29 "inner_values": {
30 "type": "array",
31 "maxItems": 2,
32 "items": {
33 "type": "string"
34 }
35 },
36 "inner_value": {
37 "type": "integer",
38 "enum": [1, 3]
39 }
40 }
41 },
42 "some_int": {
43 "type": "integer",
44 "format": "int32"
45 }
46 }
47 }
48 };
49
50 let value = json! {
51 {
52 "some_inner": {
53 "inner_value": 2,
54 "inner_values": ["value", 2]
55 },
56 "unexpected_property": 2
57 }
58 };
59
60 let schema = serde_json::from_value::<RootSchema>(schema_value).unwrap();
61 let valid = schema.verify_value(&Spanned::new(&value, KeySpans::default()));
62
63 if let Err(errors) = valid {
64 for error in errors {
65 println!(
66 "({span}) {err}",
67 span = error.span.map(|s| s.dotted()).unwrap_or_default(),
68 err = error.value
69 )
70 }
71 }
72 // (some_inner.inner_value) invalid enum value, expected to be one of {1, 3}
73 // (some_inner.inner_values.1) invalid type, expected "String"
74 // (unexpected_property) value is not allowed here
75 // () the required property "some_int" is missing
76}
Sourcepub fn into_inner(self) -> SmallVec<[String; 10]>
pub fn into_inner(self) -> SmallVec<[String; 10]>
Return the inner container.
Trait Implementations§
Source§impl AddAssign for Keys
impl AddAssign for Keys
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moreSource§impl IntoIterator for Keys
impl IntoIterator for Keys
impl Eq for Keys
impl Span for Keys
impl StructuralPartialEq for Keys
Auto Trait Implementations§
impl Freeze for Keys
impl RefUnwindSafe for Keys
impl Send for Keys
impl Sync for Keys
impl Unpin for Keys
impl UnwindSafe for Keys
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more