Struct Keys

Source
pub struct Keys(/* private fields */);
Expand description

A span consisting of consecutive string keys.

Implementations§

Source§

impl Keys

Source

pub fn new() -> Self

Create a new instance with no keys.

Source

pub fn with_capacity(cap: usize) -> Self

Create a new empty instance with a capacity.

Source

pub fn iter(&self) -> impl Iterator<Item = &String>

Iterator over the keys.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut String>

Mutable Iterator over the keys.

Source

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}
Source

pub fn push(&mut self, value: String)

Add a new key.

Source

pub fn into_inner(self) -> SmallVec<[String; 10]>

Return the inner container.

Trait Implementations§

Source§

impl<S: ToString> Add<S> for Keys

Source§

type Output = Keys

The resulting type after applying the + operator.
Source§

fn add(self, rhs: S) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Keys

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Keys

Source§

fn clone(&self) -> Keys

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Keys

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Keys

Source§

fn default() -> Keys

Returns the “default value” for a type. Read more
Source§

impl From<String> for Keys

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl IntoIterator for Keys

Source§

type Item = <SmallVec<[String; 10]> as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<[String; 10]>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Keys

Source§

fn eq(&self, other: &Keys) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Keys

Source§

impl Span for Keys

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

unsafe fn clone_box(&self) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<S> SpanExt for S
where S: Span,

Source§

fn combine(&mut self, span: S)

Combine two Span-like types. It is useful for spans wrapped in Options.
Source§

fn combined(&self, span: Self) -> Self

Clones and combines two Span-like types. It is useful for spans wrapped in Options.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.