| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 2 | hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, |
| 3 | syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::{AtomicPtrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicPtr#, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#}, |
| 4 | }; |
| 5 | |
| 6 | use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Valuerust-analyzer cargo serde_json 1.0.145 value/Value#; |
| 7 | |
| 8 | mod keysrust-analyzer cargo referencing 0.37.4 anchors/keys/; |
| 9 | |
| 10 | use craterust-analyzer cargo referencing 0.37.4 crate/::{resourcerust-analyzer cargo referencing 0.37.4 resource/::InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#, Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, Errorrust-analyzer cargo referencing 0.37.4 error/Error#, Resolvedrust-analyzer cargo referencing 0.37.4 resolver/Resolved#, Resolverrust-analyzer cargo referencing 0.37.4 resolver/Resolver#}; |
| 11 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) use keysrust-analyzer cargo referencing 0.37.4 anchors/keys/::{AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#, AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#}; |
| 12 | |
| 13 | #[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:)] |
| 14 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) struct AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName# { |
| 15 | ptrrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#ptr.: AtomicPtrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicPtr#<u8>, |
| 16 | lenrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#len.: usize, |
| 17 | } |
| 18 | |
| 19 | impl AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName# { |
| 20 | fn newrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]new().(s: &str) -> Selfrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName] { |
| 21 | Selfrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName] { |
| 22 | ptrrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#ptr.: AtomicPtrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicPtr#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[`AtomicPtr<T>`]new().(s.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().().cast_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast_mut().()), |
| 23 | lenrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#len.: s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().(), |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | #[allow(unsafe_code)] |
| 28 | fn as_strrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]as_str().(&self) -> &str { |
| 29 | // SAFETY: The pointer is valid as long as the registry exists |
| 30 | unsafe { |
| 31 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8_unchecked().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::from_raw_partsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/raw/from_raw_parts().( |
| 32 | self.ptrrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#ptr..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[`AtomicPtr<T>`]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#), |
| 33 | self.lenrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#len., |
| 34 | )) |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName# { |
| 40 | fn clonerust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName][Clone]clone().(&self) -> Selfrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName][Clone] { |
| 41 | Selfrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName][Clone] { |
| 42 | ptrrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#ptr.: AtomicPtrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicPtr#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[`AtomicPtr<T>`]new().(self.ptrrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#ptr..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[`AtomicPtr<T>`]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#)), |
| 43 | lenrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#len.: self.lenrust-analyzer cargo referencing 0.37.4 anchors/AnchorName#len., |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | impl Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName# { |
| 49 | fn hashrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName][Hash]hash().<H: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) { |
| 50 | self.as_strrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]as_str().().hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[str][Hash]hash().(state); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName# { |
| 55 | fn eqrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName][`PartialEq<Self>`]) -> bool { |
| 56 | self.as_strrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().other.as_strrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]as_str().() |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | impl Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName# {} |
| 61 | |
| 62 | /// An anchor within a resource. |
| 63 | #[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:)] |
| 64 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) enum Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor# { |
| 65 | Defaultrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default# { |
| 66 | namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#name.: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#, |
| 67 | resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#resource.: InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#, |
| 68 | }, |
| 69 | Dynamicrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic# { |
| 70 | namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic#name.: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#, |
| 71 | resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic#resource.: InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#, |
| 72 | }, |
| 73 | } |
| 74 | |
| 75 | impl Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor# { |
| 76 | /// Anchor's name. |
| 77 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn namerust-analyzer cargo referencing 0.37.4 anchors/impl#[Anchor]name().(&self) -> AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName# { |
| 78 | match self { |
| 79 | Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Defaultrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default# { namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#name., .. } | Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Dynamicrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic# { namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic#name., .. } => name.clonerust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName][Clone]clone().(), |
| 80 | } |
| 81 | } |
| 82 | /// Get the resource for this anchor. |
| 83 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn resolverust-analyzer cargo referencing 0.37.4 anchors/impl#[Anchor]resolve().<'r>(&'r self, resolver: Resolverrust-analyzer cargo referencing 0.37.4 resolver/Resolver#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Resolvedrust-analyzer cargo referencing 0.37.4 resolver/Resolved#<'r>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 84 | match self { |
| 85 | Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Defaultrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default# { resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#resource., .. } => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Resolvedrust-analyzer cargo referencing 0.37.4 resolver/Resolved#::newrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]new().( |
| 86 | resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().(), |
| 87 | resolver, |
| 88 | resource.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]draft().(), |
| 89 | )), |
| 90 | Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Dynamicrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic# { namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic#name., resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic#resource. } => { |
| 91 | let mut last = resource; |
| 92 | for uri in &resolver.dynamic_scoperust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]dynamic_scope().() { |
| 93 | match resolver.registryrust-analyzer cargo referencing 0.37.4 resolver/Resolver#registry..anchorrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]anchor().(uri, name.as_strrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]as_str().()) { |
| 94 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(anchor) => { |
| 95 | if let Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Dynamicrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic# { resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic#resource., .. } = anchor { |
| 96 | last = resource; |
| 97 | } |
| 98 | } |
| 99 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo referencing 0.37.4 error/Error#::NoSuchAnchorrust-analyzer cargo referencing 0.37.4 error/Error#NoSuchAnchor# { .. }) => {} |
| 100 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err), |
| 101 | } |
| 102 | } |
| 103 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Resolvedrust-analyzer cargo referencing 0.37.4 resolver/Resolved#::newrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]new().( |
| 104 | last.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]contents().(), |
| 105 | resolver.in_subresource_innerrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]in_subresource_inner().(last)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 106 | last.draftrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]draft().(), |
| 107 | )) |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) enum AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter# { |
| 114 | Emptyrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Empty#, |
| 115 | Onerust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#One#(Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#), |
| 116 | Tworust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Two#(Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#, Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#), |
| 117 | } |
| 118 | |
| 119 | impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter# { |
| 120 | type Itemrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorIter][Iterator]Item# = Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#; |
| 121 | |
| 122 | fn nextrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorIter][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorIter][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 123 | match stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(self, AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Emptyrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Empty#) { |
| 124 | AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Emptyrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Empty# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 125 | AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Onerust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#One#(anchor) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(anchor), |
| 126 | AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Tworust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Two#(first, second) => { |
| 127 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Onerust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#One#(second); |
| 128 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first) |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn anchorrust-analyzer cargo referencing 0.37.4 anchors/anchor().(draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter# { |
| 135 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(schema) = contents.as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().() else { |
| 136 | return AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Emptyrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Empty#; |
| 137 | }; |
| 138 | |
| 139 | // First check for top-level anchors |
| 140 | let default_anchor = |
| 141 | schema |
| 142 | .getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("$anchor") |
| 143 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().) |
| 144 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|name| Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Defaultrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default# { |
| 145 | namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#name.: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#::newrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]new().(name), |
| 146 | resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#resource.: InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().(contents, draft), |
| 147 | }); |
| 148 | |
| 149 | let dynamic_anchor = schema |
| 150 | .getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("$dynamicAnchor") |
| 151 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().) |
| 152 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|name| Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Dynamicrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic# { |
| 153 | namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic#name.: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#::newrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]new().(name), |
| 154 | resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Dynamic#resource.: InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().(contents, draft), |
| 155 | }); |
| 156 | |
| 157 | match (default_anchor, dynamic_anchor) { |
| 158 | (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(default), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dynamic)) => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Tworust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Two#(default, dynamic), |
| 159 | (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(default), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Onerust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#One#(default), |
| 160 | (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dynamic)) => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Onerust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#One#(dynamic), |
| 161 | (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Emptyrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Empty#, |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn anchor_2019rust-analyzer cargo referencing 0.37.4 anchors/anchor_2019().(draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter# { |
| 166 | match contents |
| 167 | .as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().() |
| 168 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|schema| schema.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("$anchor")) |
| 169 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().) |
| 170 | { |
| 171 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Onerust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#One#(Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Defaultrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default# { |
| 172 | namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#name.: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#::newrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]new().(name), |
| 173 | resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#resource.: InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().(contents, draft), |
| 174 | }), |
| 175 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Emptyrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Empty#, |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn legacy_anchor_in_dollar_idrust-analyzer cargo referencing 0.37.4 anchors/legacy_anchor_in_dollar_id().(draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter# { |
| 180 | match contents |
| 181 | .as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().() |
| 182 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|schema| schema.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("$id")) |
| 183 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().) |
| 184 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|id| id.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().('#')) |
| 185 | { |
| 186 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Onerust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#One#(Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Defaultrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default# { |
| 187 | namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#name.: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#::newrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]new().(id), |
| 188 | resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#resource.: InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().(contents, draft), |
| 189 | }), |
| 190 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Emptyrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Empty#, |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn legacy_anchor_in_idrust-analyzer cargo referencing 0.37.4 anchors/legacy_anchor_in_id().(draft: Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, contents: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter# { |
| 195 | match contents |
| 196 | .as_objectrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_object().() |
| 197 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|schema| schema.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("id")) |
| 198 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::as_strrust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_str().) |
| 199 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|id| id.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().('#')) |
| 200 | { |
| 201 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Onerust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#One#(Anchorrust-analyzer cargo referencing 0.37.4 anchors/Anchor#::Defaultrust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default# { |
| 202 | namerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#name.: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#::newrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]new().(id), |
| 203 | resourcerust-analyzer cargo referencing 0.37.4 anchors/Anchor#Default#resource.: InnerResourcePtrrust-analyzer cargo referencing 0.37.4 resource/InnerResourcePtr#::newrust-analyzer cargo referencing 0.37.4 resource/impl#[InnerResourcePtr]new().(contents, draft), |
| 204 | }), |
| 205 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => AnchorIterrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#::Emptyrust-analyzer cargo referencing 0.37.4 anchors/AnchorIter#Empty#, |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | #[cfg(test)] |
| 210 | mod testsrust-analyzer cargo referencing 0.37.4 anchors/tests/ { |
| 211 | use craterust-analyzer cargo referencing 0.37.4 crate/::{Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#, Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#}; |
| 212 | use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::jsonrust-analyzer cargo serde_json 1.0.145 macros/json!; |
| 213 | |
| 214 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 215 | fn test_lookup_trivial_dynamic_refrust-analyzer cargo referencing 0.37.4 anchors/tests/test_lookup_trivial_dynamic_ref().() { |
| 216 | let one = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$dynamicAnchor": "foo"})); |
| 217 | let registry = |
| 218 | Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("http://example.com", one.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 219 | let resolver = registry |
| 220 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 221 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 222 | let resolved = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("#foo").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 223 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(resolved.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), one.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]contents().()); |
| 224 | } |
| 225 | |
| 226 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 227 | fn test_multiple_lookup_trivial_dynamic_refrust-analyzer cargo referencing 0.37.4 anchors/tests/test_multiple_lookup_trivial_dynamic_ref().() { |
| 228 | let true_resource = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(true)); |
| 229 | let root = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 230 | "$id": "http://example.com", |
| 231 | "$dynamicAnchor": "fooAnchor", |
| 232 | "$defs": { |
| 233 | "foo": { |
| 234 | "$id": "foo", |
| 235 | "$dynamicAnchor": "fooAnchor", |
| 236 | "$defs": { |
| 237 | "bar": true, |
| 238 | "baz": { |
| 239 | "$dynamicAnchor": "fooAnchor", |
| 240 | }, |
| 241 | }, |
| 242 | }, |
| 243 | }, |
| 244 | })); |
| 245 | |
| 246 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources().([ |
| 247 | ("http://example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), root.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()), |
| 248 | ("http://example.com/foo/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), true_resource), |
| 249 | ("http://example.com/foo/bar".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), root.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()), |
| 250 | ]) |
| 251 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 252 | let resolver = registry |
| 253 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 254 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 255 | |
| 256 | let first = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 257 | let second = first.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().().lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("foo/").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 258 | let third = second.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().().lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("bar").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 259 | let fourth = third |
| 260 | .resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().() |
| 261 | .lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("#fooAnchor") |
| 262 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 263 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fourth.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), root.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]contents().()); |
| 264 | 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!!("{:?}", fourth.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().()), "Resolver { base_uri: \"http://example.com\", scopes: \"[http://example.com/foo/, http://example.com, http://example.com]\" }"); |
| 265 | } |
| 266 | |
| 267 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 268 | fn test_multiple_lookup_dynamic_ref_to_nondynamic_refrust-analyzer cargo referencing 0.37.4 anchors/tests/test_multiple_lookup_dynamic_ref_to_nondynamic_ref().() { |
| 269 | let one = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$anchor": "fooAnchor"})); |
| 270 | let two = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 271 | "$id": "http://example.com", |
| 272 | "$dynamicAnchor": "fooAnchor", |
| 273 | "$defs": { |
| 274 | "foo": { |
| 275 | "$id": "foo", |
| 276 | "$dynamicAnchor": "fooAnchor", |
| 277 | "$defs": { |
| 278 | "bar": true, |
| 279 | "baz": { |
| 280 | "$dynamicAnchor": "fooAnchor", |
| 281 | }, |
| 282 | }, |
| 283 | }, |
| 284 | }, |
| 285 | })); |
| 286 | |
| 287 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources().([ |
| 288 | ("http://example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), two.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()), |
| 289 | ("http://example.com/foo/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), one), |
| 290 | ("http://example.com/foo/bar".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), two.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()), |
| 291 | ]) |
| 292 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 293 | let resolver = registry |
| 294 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 295 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 296 | |
| 297 | let first = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 298 | let second = first.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().().lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("foo/").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 299 | let third = second.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().().lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("bar").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 300 | let fourth = third |
| 301 | .resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().() |
| 302 | .lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("#fooAnchor") |
| 303 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 304 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fourth.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), two.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]contents().()); |
| 305 | } |
| 306 | |
| 307 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 308 | fn test_unknown_anchorrust-analyzer cargo referencing 0.37.4 anchors/tests/test_unknown_anchor().() { |
| 309 | let schema = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 310 | "$defs": { |
| 311 | "foo": { "$anchor": "knownAnchor" } |
| 312 | } |
| 313 | })); |
| 314 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("http://example.com", schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 315 | let resolver = registry |
| 316 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 317 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 318 | |
| 319 | let result = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("#unknownAnchor"); |
| 320 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 321 | result.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 322 | "Anchor 'unknownAnchor' does not exist" |
| 323 | ); |
| 324 | } |
| 325 | |
| 326 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 327 | fn test_invalid_anchor_with_slashrust-analyzer cargo referencing 0.37.4 anchors/tests/test_invalid_anchor_with_slash().() { |
| 328 | let schema = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft202012rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft202012#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 329 | "$defs": { |
| 330 | "foo": { "$anchor": "knownAnchor" } |
| 331 | } |
| 332 | })); |
| 333 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("http://example.com", schema).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 334 | let resolver = registry |
| 335 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 336 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 337 | |
| 338 | let result = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("#invalid/anchor"); |
| 339 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 340 | result.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 341 | "Anchor 'invalid/anchor' is invalid" |
| 342 | ); |
| 343 | } |
| 344 | |
| 345 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 346 | fn test_lookup_trivial_recursive_refrust-analyzer cargo referencing 0.37.4 anchors/tests/test_lookup_trivial_recursive_ref().() { |
| 347 | let one = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft201909rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft201909#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$recursiveAnchor": true})); |
| 348 | let registry = |
| 349 | Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("http://example.com", one.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 350 | let resolver = registry |
| 351 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 352 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 353 | let first = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 354 | let resolved = first |
| 355 | .resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().() |
| 356 | .lookup_recursive_refrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup_recursive_ref().() |
| 357 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 358 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(resolved.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), one.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]contents().()); |
| 359 | } |
| 360 | |
| 361 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 362 | fn test_lookup_recursive_ref_to_boolrust-analyzer cargo referencing 0.37.4 anchors/tests/test_lookup_recursive_ref_to_bool().() { |
| 363 | let true_resource = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft201909rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft201909#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(true)); |
| 364 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_newrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_new().("http://example.com", true_resource.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()) |
| 365 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 366 | let resolver = registry |
| 367 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 368 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 369 | let resolved = resolver.lookup_recursive_refrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup_recursive_ref().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 370 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(resolved.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), true_resource.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]contents().()); |
| 371 | } |
| 372 | |
| 373 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 374 | fn test_multiple_lookup_recursive_ref_to_boolrust-analyzer cargo referencing 0.37.4 anchors/tests/test_multiple_lookup_recursive_ref_to_bool().() { |
| 375 | let true_resource = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft201909rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft201909#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(true)); |
| 376 | let root = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft201909rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft201909#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 377 | "$id": "http://example.com", |
| 378 | "$recursiveAnchor": true, |
| 379 | "$defs": { |
| 380 | "foo": { |
| 381 | "$id": "foo", |
| 382 | "$recursiveAnchor": true, |
| 383 | "$defs": { |
| 384 | "bar": true, |
| 385 | "baz": { |
| 386 | "$recursiveAnchor": true, |
| 387 | "$anchor": "fooAnchor", |
| 388 | }, |
| 389 | }, |
| 390 | }, |
| 391 | }, |
| 392 | })); |
| 393 | |
| 394 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 395 | ("http://example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), root.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()), |
| 396 | ("http://example.com/foo/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), true_resource), |
| 397 | ("http://example.com/foo/bar".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), root.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()), |
| 398 | ]) |
| 399 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 400 | |
| 401 | let resolver = registry |
| 402 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 403 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 404 | let first = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 405 | let second = first.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().().lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("foo/").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 406 | let third = second.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().().lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("bar").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 407 | let fourth = third |
| 408 | .resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().() |
| 409 | .lookup_recursive_refrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup_recursive_ref().() |
| 410 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 411 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fourth.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), root.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]contents().()); |
| 412 | } |
| 413 | |
| 414 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 415 | fn test_multiple_lookup_recursive_ref_with_nonrecursive_refrust-analyzer cargo referencing 0.37.4 anchors/tests/test_multiple_lookup_recursive_ref_with_nonrecursive_ref().() { |
| 416 | let one = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft201909rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft201909#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$recursiveAnchor": true})); |
| 417 | let two = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft201909rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft201909#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({ |
| 418 | "$id": "http://example.com", |
| 419 | "$recursiveAnchor": true, |
| 420 | "$defs": { |
| 421 | "foo": { |
| 422 | "$id": "foo", |
| 423 | "$recursiveAnchor": true, |
| 424 | "$defs": { |
| 425 | "bar": true, |
| 426 | "baz": { |
| 427 | "$recursiveAnchor": true, |
| 428 | "$anchor": "fooAnchor", |
| 429 | }, |
| 430 | }, |
| 431 | }, |
| 432 | }, |
| 433 | })); |
| 434 | let three = Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#::Draft201909rust-analyzer cargo referencing 0.37.4 specification/Draft#Draft201909#.create_resourcerust-analyzer cargo referencing 0.37.4 specification/impl#[Draft]create_resource().(jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"$recursiveAnchor": false})); |
| 435 | |
| 436 | let registry = Registryrust-analyzer cargo referencing 0.37.4 registry/Registry#::try_from_resourcesrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_from_resources().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 437 | ("http://example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), three), |
| 438 | ("http://example.com/foo/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), two.clonerust-analyzer cargo referencing 0.37.4 resource/impl#[Resource][Clone]clone().()), |
| 439 | ("http://example.com/foo/bar".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), one), |
| 440 | ]) |
| 441 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid resources"); |
| 442 | |
| 443 | let resolver = registry |
| 444 | .try_resolverrust-analyzer cargo referencing 0.37.4 registry/impl#[Registry]try_resolver().("http://example.com") |
| 445 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Invalid base URI"); |
| 446 | let first = resolver.lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 447 | let second = first.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().().lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("foo/").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 448 | let third = second.resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().().lookuprust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup().("bar").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 449 | let fourth = third |
| 450 | .resolverrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]resolver().() |
| 451 | .lookup_recursive_refrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolver<'r>`]lookup_recursive_ref().() |
| 452 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Lookup failed"); |
| 453 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fourth.contentsrust-analyzer cargo referencing 0.37.4 resolver/impl#[`Resolved<'r>`]contents().(), two.contentsrust-analyzer cargo referencing 0.37.4 resource/impl#[Resource]contents().()); |
| 454 | } |
| 455 | } |