Debian Codegraph @

src/paths.rs

raw symbols SCIP
1 //! Facilities for working with paths within schemas or validated instances.
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#};
3
4 use referencingrust-analyzer cargo referencing 0.37.4 crate/::unescape_segmentrust-analyzer cargo referencing 0.37.4 resource/unescape_segment().;
5
6 use craterust-analyzer cargo jsonschema 0.37.4 crate/::keywordsrust-analyzer cargo jsonschema 0.37.4 keywords/::Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/Keyword#;
7
8 /// A location segment.
9 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
10 pub enum LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a> {
11 /// Property name within a JSON object.
12 Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>),
13 /// JSON Schema keyword.
14 Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(usize),
15 }
16
17 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'_> {
18 fn fmtrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'_>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
19 match self {
20 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(property) => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(property),
21 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(idx) => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(itoarust-analyzer cargo itoa 1.0.15 crate/::Bufferrust-analyzer cargo itoa 1.0.15 Buffer#::newrust-analyzer cargo itoa 1.0.15 impl#[Buffer]new().().formatrust-analyzer cargo itoa 1.0.15 impl#[Buffer]format().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().idx)),
22 }
23 }
24 }
25
26 /// A lazily constructed location within a JSON instance.
27 ///
28 /// [`LazyLocation`] builds a path incrementally during JSON Schema validation without allocating
29 /// memory until required by storing each segment on the stack.
30 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
31 pub struct LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#<'a, 'b> {
32 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) segmentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#segment.: LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a>,
33 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) parentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#parent.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'b LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#<'b, 'a>>,
34 }
35
36 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#<'_, '_> {
37 fn defaultrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'_, '_>`][Default]default().() -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'_, '_>`][Default] {
38 LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]new().()
39 }
40 }
41
42 impl<'a> LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#<'a, '_> {
43 /// Create a root node of a JSON pointer.
44 #[must_use]
45 pub const fn newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]new().() -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`] {
46 LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation# {
47 // The value does not matter, it will never be used
48 segmentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#segment.: LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(0),
49 parentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#parent.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
50 }
51 }
52
53 /// Push a new segment to the JSON pointer.
54 #[inline]
55 #[must_use]
56 pub fn pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(&'a self, segment: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a>>) -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`] {
57 LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation# {
58 segmentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#segment.: segment.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(),
59 parentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#parent.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self),
60 }
61 }
62 }
63
64 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#<'_, '_>> for Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location# {
65 fn fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][`From<&'a LazyLocation<'_, '_>>`]from().(value: &'a LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#<'_, '_>) -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][`From<&'a LazyLocation<'_, '_>>`] {
66 let mut capacity = 0;
67 let mut string_capacity = 0;
68 let mut head = value;
69
70 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next) = head.parentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#parent. {
71 capacity rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
72 string_capacity rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().match &head.segmentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#segment. {
73 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(property) => property.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1,
74 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(idx) => idx.checked_ilog10rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_ilog10().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0) as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2,
75 };
76 head = next;
77 }
78
79 let mut buffer = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(string_capacity);
80
81 let mut segments = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity);
82 head = value;
83
84 if head.parentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#parent..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
85 segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(head.segmentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#segment..clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][Clone]clone().());
86 }
87
88 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next) = head.parentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#parent. {
89 head = next;
90 if head.parentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#parent..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
91 segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(head.segmentrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#segment..clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][Clone]clone().());
92 }
93 }
94
95 for segment in segments.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() {
96 buffer.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('/');
97 match segment {
98 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(property) => {
99 write_escaped_strrust-analyzer cargo jsonschema 0.37.4 paths/write_escaped_str().(&mut buffer, property);
100 }
101 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(idx) => {
102 let mut itoa_buffer = itoarust-analyzer cargo itoa 1.0.15 crate/::Bufferrust-analyzer cargo itoa 1.0.15 Buffer#::newrust-analyzer cargo itoa 1.0.15 impl#[Buffer]new().();
103 buffer.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(itoa_buffer.formatrust-analyzer cargo itoa 1.0.15 impl#[Buffer]format().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().idx));
104 }
105 }
106 }
107
108 Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<str>`][`From<String>`]from().(buffer))
109 }
110 }
111
112 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/Keyword#> for LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a> {
113 fn fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a Keyword>`]from().(value: &'a Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/Keyword#) -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a Keyword>`] {
114 match value {
115 Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/Keyword#::Builtinrust-analyzer cargo jsonschema 0.37.4 keywords/Keyword#Builtin#(k) => LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(k.as_strrust-analyzer cargo jsonschema 0.37.4 keywords/impl#[BuiltinKeyword]as_str().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
116 Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/Keyword#::Customrust-analyzer cargo jsonschema 0.37.4 keywords/Keyword#Custom#(s) => LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(s)),
117 }
118 }
119 }
120
121 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a str> for LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a> {
122 #[inline]
123 fn fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().(value: &'a str) -> LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a> {
124 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(value))
125 }
126 }
127
128 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a> {
129 #[inline]
130 fn fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a String>`]from().(value: &'a Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a> {
131 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(value))
132 }
133 }
134
135 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>> for LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a> {
136 #[inline]
137 fn fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<Cow<'a, str>>`]from().(value: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>) -> LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a> {
138 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(value)
139 }
140 }
141
142 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<usize> for LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'_> {
143 #[inline]
144 fn fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'_>`][`From<usize>`]from().(value: usize) -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'_>`][`From<usize>`] {
145 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(value)
146 }
147 }
148
149 /// A cheap to clone JSON pointer that represents location with a JSON value.
150 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)]
151 pub struct Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<str>);
152
153 impl serderust-analyzer cargo serde 1.0.228 crate/::Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize# for Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location# {
154 fn serializerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Serialize]serialize().<S>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.228 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.228 ser/Serializer#Error#>
155 where
156 S: serderust-analyzer cargo serde 1.0.228 crate/::Serializerrust-analyzer cargo serde_core 1.0.228 ser/Serializer#,
157 {
158 serializer.serialize_strrust-analyzer cargo serde_core 1.0.228 ser/Serializer#serialize_str().(&self.0rust-analyzer cargo jsonschema 0.37.4 paths/Location#0.)
159 }
160 }
161
162 impl Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location# {
163 /// Create a new, empty `Location`.
164 #[must_use]
165 pub fn newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().() -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location] {
166 Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location](Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<str>`][`From<&str>`]from().(""))
167 }
168 #[must_use]
169 pub fn joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().<'a>(&self, segment: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a>>) -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location] {
170 let parent = &self.0rust-analyzer cargo jsonschema 0.37.4 paths/Location#0.;
171 match segment.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().() {
172 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(property) => {
173 let mut buffer = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(parent.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().property.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1);
174 buffer.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(parent);
175 buffer.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('/');
176 write_escaped_strrust-analyzer cargo jsonschema 0.37.4 paths/write_escaped_str().(&mut buffer, &property);
177 Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location](Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<str>`][`From<String>`]from().(buffer))
178 }
179 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(idx) => {
180 let mut buffer = itoarust-analyzer cargo itoa 1.0.15 crate/::Bufferrust-analyzer cargo itoa 1.0.15 Buffer#::newrust-analyzer cargo itoa 1.0.15 impl#[Buffer]new().();
181 let segment = buffer.formatrust-analyzer cargo itoa 1.0.15 impl#[Buffer]format().(idx);
182 Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location](Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<str>`][`From<String>`]from().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{parent}/{segment}")))
183 }
184 }
185 }
186 /// Get a clone of the inner `Arc<str>` representing the location.
187 #[must_use]
188 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn as_arcrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_arc().(&self) -> Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<str> {
189 Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&self.0rust-analyzer cargo jsonschema 0.37.4 paths/Location#0.)
190 }
191
192 /// Get a string slice representing the location.
193 #[must_use]
194 pub fn as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(&self) -> &str {
195 &self.0rust-analyzer cargo jsonschema 0.37.4 paths/Location#0.
196 }
197 /// Get a byte slice representing the location.
198 #[must_use]
199 pub fn as_bytesrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_bytes().(&self) -> &[u8] {
200 self.0rust-analyzer cargo jsonschema 0.37.4 paths/Location#0..as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()
201 }
202
203 #[must_use]
204 pub fn iterrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]iter().(&self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::IntoIterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/IntoIter#<LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'_>> {
205 <&Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location] as IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#>::into_iterrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`&'a Location`][IntoIterator]into_iter().(self)
206 }
207 }
208
209 pub fn write_escaped_strrust-analyzer cargo jsonschema 0.37.4 paths/write_escaped_str().(buffer: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, value: &str) {
210 match value.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(['~', '/']) {
211 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut escape_idx) => {
212 let mut remaining = value;
213
214 // Loop through the string to replace `~` and `/`
215 loop {
216 let (before, after) = remaining.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_at().(escape_idx);
217 // Copy everything before the escape char
218 buffer.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(before);
219
220 // Append the appropriate escape sequence
221 match after.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). {
222 b'~' => buffer.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("~0"),
223 b'/' => buffer.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("~1"),
224 _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(),
225 }
226
227 // Move past the escaped character
228 remaining = &after[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
229
230 // Find the next `~` or `/` to continue escaping
231 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next_escape_idx) = remaining.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(['~', '/']) {
232 escape_idx = next_escape_idx;
233 } else {
234 // Append any remaining part of the string
235 buffer.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(remaining);
236 break;
237 }
238 }
239 }
240 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
241 // If no escape characters are found, append the segment as is
242 buffer.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(value);
243 }
244 }
245 }
246
247 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location# {
248 fn defaultrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Default]default().() -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Default] {
249 Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Default]::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().()
250 }
251 }
252
253 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location# {
254 fn fmtrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
255 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(self.as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().())
256 }
257 }
258
259 impl<'a> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for &'a Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location# {
260 type Itemrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`&'a Location`][IntoIterator]Item# = LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a>;
261 type IntoIterrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`&'a Location`][IntoIterator]IntoIter# = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::IntoIterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/IntoIter#<LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a>>;
262
263 fn into_iterrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`&'a Location`][IntoIterator]into_iter().(self) -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`&'a Location`][IntoIterator]::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter# {
264 self.as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().()
265 .splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('/')
266 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|p| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().p.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().())
267 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|p| {
268 p.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<usize>().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_or().(
269 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(unescape_segmentrust-analyzer cargo referencing 0.37.4 resource/unescape_segment().(p)),
270 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#,
271 )
272 })
273 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()
274 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
275 }
276 }
277
278 impl<'a> FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a>> for Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location# {
279 fn from_iterrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][`FromIterator<LocationSegment<'a>>`]from_iter().<T>(iter: T) -> Selfrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][`FromIterator<LocationSegment<'a>>`]
280 where
281 T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'a>>,
282 {
283 fn innerrust-analyzer cargo jsonschema 0.37.4 paths/inner().<'a, 'b, 'c, I>(path_iter: &mut I, location: &'b LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#<'b, 'a>) -> Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#
284 where
285 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#<'c>>,
286 {
287 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) = path_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() else {
288 return location.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
289 };
290 let location = location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(path);
291 innerrust-analyzer cargo jsonschema 0.37.4 paths/inner().(path_iter, &location)
292 }
293
294 let loc = LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#::defaultrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'_, '_>`][Default]default().();
295 innerrust-analyzer cargo jsonschema 0.37.4 paths/inner().(&mut iter.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(), &loc)
296 }
297 }
298
299 #[cfg(test)]
300 mod testsrust-analyzer cargo jsonschema 0.37.4 paths/tests/ {
301 use superrust-analyzer cargo jsonschema 0.37.4 paths/::*;
302 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::jsonrust-analyzer cargo serde_json 1.0.145 macros/json!;
303 use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:;
304
305 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
306 fn test_location_defaultrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_location_default().() {
307 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::defaultrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Default]default().();
308 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc.as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(), "");
309 }
310
311 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
312 fn test_location_newrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_location_new().() {
313 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().();
314 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc.as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(), "");
315 }
316
317 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
318 fn test_location_join_propertyrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_location_join_property().() {
319 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().();
320 let loc = loc.joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("property");
321 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc.as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(), "/property");
322 }
323
324 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
325 fn test_location_join_indexrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_location_join_index().() {
326 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().();
327 let loc = loc.joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().(0);
328 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc.as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(), "/0");
329 }
330
331 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
332 fn test_location_join_multiplerust-analyzer cargo jsonschema 0.37.4 paths/tests/test_location_join_multiple().() {
333 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().();
334 let loc = loc.joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("property").joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().(0);
335 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc.as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(), "/property/0");
336 }
337
338 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
339 fn test_as_bytesrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_as_bytes().() {
340 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("test");
341 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc.as_bytesrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_bytes().(), b"/test");
342 }
343
344 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
345 fn test_display_traitrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_display_trait().() {
346 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("property");
347 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{loc}"), "/property");
348 }
349
350 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("tilde~character", "/tilde~0character"; "escapes tilde")]
351 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("slash/character", "/slash~1character"; "escapes slash")]
352 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("combo~and/slash", "/combo~0and~1slash"; "escapes tilde and slash combined")]
353 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("multiple~/escapes~", "/multiple~0~1escapes~0"; "multiple escapes")]
354 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("first/segment", "/first~1segment"; "escapes slash in nested segment")]
355 fn test_location_escapingrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_location_escaping().(segment: &str, expected: &str) {
356 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().(segment);
357 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc.as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(), expected);
358 }
359
360 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("/a/b/c", &[LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().("a"), LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().("b"), LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().("c")]; "location with properties")]
361 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("/1/2/3", &[LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(1), LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(2), LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(3)]; "location with indices")]
362 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("/a/1/b/2", &[
363 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().("a"),
364 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(1),
365 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().("b"),
366 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(2)
367 ]; "mixed properties and indices")]
368 fn test_into_iterrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_into_iter().(location: &str, expected_segments: &[LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#]) {
369 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<str>`][`From<String>`]from().(location.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
370 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc.into_iterrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`&'a Location`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), expected_segments);
371 }
372
373 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().("a"), LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().("b")], "/a/b"; "properties only")]
374 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(1), LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(2)], "/1/2"; "indices only")]
375 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::fromrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LocationSegment<'a>`][`From<&'a str>`]from().("a"), LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(1)], "/a/1"; "mixed segments")]
376 fn test_from_iterrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_from_iter().(segments: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#>, expected: &str) {
377 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::from_iterrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][`FromIterator<LocationSegment<'a>>`]from_iter().(segments).as_strrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]as_str().(), expected);
378 }
379
380 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
381 fn test_roundtrip_join_iter_rebuild_equalsrust-analyzer cargo jsonschema 0.37.4 paths/tests/test_roundtrip_join_iter_rebuild_equals().() {
382 let loc = Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("a/b").joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().(2).joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("x~y");
383
384 let segments: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = loc.into_iterrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`&'a Location`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
385
386 let rebuilt = segments
387 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
388 .foldrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]fold().(Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), |acc, seg| match seg {
389 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(p) => acc.joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().(p),
390 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(i) => acc.joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().(i),
391 });
392
393 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(loc, rebuilt);
394 }
395
396 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
397 fn test_validate_error_instance_path_traverses_instancerust-analyzer cargo jsonschema 0.37.4 paths/tests/test_validate_error_instance_path_traverses_instance().() {
398 let schema = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({
399 "type": "object",
400 "properties": {
401 "table-node": {
402 "type": "array",
403 "items": {
404 "type": "object",
405 "properties": { "~": { "type": "string", "minLength": 1 } },
406 "required": ["~"],
407 }
408 }
409 },
410 "$schema": "https://json-schema.org/draft/2020-12/schema",
411 });
412 let instance = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({
413 "table-node": [
414 { "~": "" },
415 { "other-value": "" },
416 ],
417 });
418
419 let error = craterust-analyzer cargo jsonschema 0.37.4 crate/::validaterust-analyzer cargo jsonschema 0.37.4 validate().(&schema, &instance).expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should fail");
420
421 // Traverse instance using the `instance_path`` segments
422 let mut current = &instance;
423 for segment in error.instance_pathrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]instance_path().() {
424 match segment {
425 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Propertyrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Property#(property) => {
426 current = &current[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().property.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
427 }
428 LocationSegmentrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#::Indexrust-analyzer cargo jsonschema 0.37.4 paths/LocationSegment#Index#(idx) => {
429 current = &current[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
430 }
431 }
432 }
433 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
434 current,
435 instance
436 .pointerrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]pointer().("/table-node/0/~0")
437 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Pointer is valid")
438 );
439 }
440 }