| 1 | //! Ways of traversing the AST-like structure of [`Inspectable`]s. |
| 2 | //! |
| 3 | //! Refer to the [documentation here][crate::inspect#traversing]. |
| 4 | |
| 5 | use smallvecrust-analyzer cargo smallvec 1.15.1 crate/::SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#; |
| 6 | |
| 7 | use craterust-analyzer cargo bendy 0.6.1 crate/::inspectrust-analyzer cargo bendy 0.6.1 inspect/::*; |
| 8 | |
| 9 | /// A `Step` in a search path, which selects what next traversal |
| 10 | /// will be applied to an [`Inspectable`] tree. |
| 11 | /// |
| 12 | /// A search path is a list of Steps. |
| 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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 14 | pub enum Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#<'a> { |
| 15 | /// Searches for a child, which is either an [`Inspectable`] or a [Dict |
| 16 | /// Entry][crate::inspect::InDictEntry]. |
| 17 | /// Only finds the first child matching the specific condition. |
| 18 | Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Search#(Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#<'a>), |
| 19 | |
| 20 | /// Access the nth child of a List or Dict. |
| 21 | Nthrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Nth#(usize), |
| 22 | |
| 23 | /// Accesses a Dict Entry with the given key. |
| 24 | Entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Entry#(&'a [u8]), |
| 25 | |
| 26 | /// Assume current item is an Dict Entry, access the key. |
| 27 | Keyrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Key#, |
| 28 | |
| 29 | /// Assume current item is an Dict Entry, access the value. |
| 30 | Valuerust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Value#, |
| 31 | } |
| 32 | |
| 33 | /// An object that represents what to search for in a [`Step::Search`]. |
| 34 | #[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:)] |
| 35 | pub enum Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#<'a> { |
| 36 | /// Search for a String with this exact value. |
| 37 | ByteStringrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#ByteString#(&'a [u8]), |
| 38 | |
| 39 | /// Search for a Dict Entry that has this exact key. |
| 40 | DictKeyrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#DictKey#(&'a [u8]), |
| 41 | |
| 42 | /// Search for this exact integer. |
| 43 | Intrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#Int#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>), |
| 44 | } |
| 45 | |
| 46 | type Pathrust-analyzer cargo bendy 0.6.1 inspect/traverse/Path#<'a> = SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#<'a>; 20]>; |
| 47 | |
| 48 | /// A builder for a path. A path is a list of [`Step`]s undertaken to traverse |
| 49 | /// an [`Inspectable`] AST. |
| 50 | /// |
| 51 | /// Use the methods provided to add new steps to the path, then provide a reference |
| 52 | /// to the [`PathBuilder`] to one of these methods: |
| 53 | /// * [`Inspectable::find`] |
| 54 | /// * [`Inspectable::find_ref`] |
| 55 | /// * [`Inspectable::clone_and_mutate`] |
| 56 | /// * [`Inspectable::mutate`] |
| 57 | /// |
| 58 | /// Unlike the standard build pattern, no `.build()` function is needed to reify |
| 59 | /// the builder. |
| 60 | /// |
| 61 | /// The methods named `into_*` all take ownership of the PathBuilder, add the step, |
| 62 | /// then return the builder. This reduces memory allocation, but may be inconvenient. |
| 63 | /// |
| 64 | /// The methods without the `into_` prefix will create a clone of the PathBuilder, |
| 65 | /// add the step to that clone, then return the clone. This may be more convenient |
| 66 | /// if you are building multiple paths that all start with the same steps. |
| 67 | /// |
| 68 | /// The builder can contain up to 20 steps before it needs to allocate. For fuzzing, |
| 69 | /// manually building structures using the [`Inspectable`] constructor methods is |
| 70 | /// recommended instead of mutating existing [`Inspectable`]s. |
| 71 | #[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:)] |
| 72 | pub struct PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'a> { |
| 73 | pub stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps.: Pathrust-analyzer cargo bendy 0.6.1 inspect/traverse/Path#<'a>, |
| 74 | } |
| 75 | |
| 76 | impl<'obj, 'pb, 'step> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> |
| 77 | where |
| 78 | 'step: 'pb, |
| 79 | { |
| 80 | #[allow(clippy::new_without_default)] |
| 81 | pub fn newrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]new().() -> Selfrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`] { |
| 82 | PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder# { |
| 83 | stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][Default]default().(), |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /// Descend into a specific item in a list or entry in a dict, given its index. |
| 88 | /// |
| 89 | /// For dicts, MUST be followed by a call to one of: [`.key`][PathBuilder::key], |
| 90 | /// [`.into_key`][PathBuilder::into_key], [`.value`][PathBuilder::value], |
| 91 | /// or [`.into_value`][PathBuilder::into_value]. |
| 92 | pub fn into_nthrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_nth().(mut self, idx: usize) -> Selfrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`] { |
| 93 | self.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps..pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#::Nthrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Nth#(idx)); |
| 94 | self |
| 95 | } |
| 96 | |
| 97 | /// Descend into a specific item in a list or entry in a dict, given its index. |
| 98 | /// |
| 99 | /// For dicts, MUST be followed by a call to one of: [`.key`][PathBuilder::key], |
| 100 | /// [`.into_key`][PathBuilder::into_key], [`.value`][PathBuilder::value], |
| 101 | /// or [`.into_value`][PathBuilder::into_value]. |
| 102 | pub fn nthrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]nth().(&'obj self, idx: usize) -> Selfrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`] { |
| 103 | let next = self.clonerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'a>`][Clone]clone().(); |
| 104 | next.into_nthrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_nth().(idx) |
| 105 | } |
| 106 | |
| 107 | /// Access a Dict Entry that has the given key byte string. |
| 108 | /// |
| 109 | /// MUST be followed by a call to one of: [`.key`][PathBuilder::key], |
| 110 | /// [`.into_key`][PathBuilder::into_key], [`.value`][PathBuilder::value], |
| 111 | /// or [`.into_value`][PathBuilder::into_value]. |
| 112 | pub fn into_entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_entry().(mut self, entry_key: &'step [u8]) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 113 | self.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps..pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#::Entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Entry#(entry_key)); |
| 114 | self |
| 115 | } |
| 116 | |
| 117 | /// Access a Dict Entry that has the given key byte string. |
| 118 | /// |
| 119 | /// MUST be followed by a call to one of: [`.key`][PathBuilder::key], |
| 120 | /// [`.into_key`][PathBuilder::into_key], [`.value`][PathBuilder::value], |
| 121 | /// or [`.into_value`][PathBuilder::into_value]. |
| 122 | pub fn entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]entry().(&'obj self, entry_key: &'step [u8]) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 123 | let next = self.clonerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'a>`][Clone]clone().(); |
| 124 | next.into_entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_entry().(entry_key) |
| 125 | } |
| 126 | |
| 127 | /// Access the key part of a Dict Entry. |
| 128 | pub fn into_keyrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_key().(mut self) -> Selfrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`] { |
| 129 | self.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps..pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#::Keyrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Key#); |
| 130 | self |
| 131 | } |
| 132 | |
| 133 | /// Access the key part of a Dict Entry. |
| 134 | pub fn keyrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]key().(&'obj self) -> Selfrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`] { |
| 135 | let next = self.clonerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'a>`][Clone]clone().(); |
| 136 | next.into_keyrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_key().() |
| 137 | } |
| 138 | |
| 139 | /// Access the value part of a Dict Entry. |
| 140 | pub fn into_valuerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_value().(mut self) -> Selfrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`] { |
| 141 | self.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps..pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#::Valuerust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Value#); |
| 142 | self |
| 143 | } |
| 144 | |
| 145 | /// Access the value part of a Dict Entry. |
| 146 | pub fn valuerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]value().(&'obj self) -> Selfrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`] { |
| 147 | let next = self.clonerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'a>`][Clone]clone().(); |
| 148 | next.into_valuerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_value().() |
| 149 | } |
| 150 | |
| 151 | /// Search for byte strings that are not dict keys. |
| 152 | pub fn into_search_bytestringrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_search_bytestring().(mut self, bytestring: &'step [u8]) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 153 | self.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps. |
| 154 | .pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#::Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Search#(Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#::ByteStringrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#ByteString#(bytestring))); |
| 155 | self |
| 156 | } |
| 157 | |
| 158 | /// Search for byte strings that are not dict keys. |
| 159 | pub fn search_bytestringrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]search_bytestring().(&'obj self, bytestring: &'step [u8]) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 160 | let next = self.clonerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'a>`][Clone]clone().(); |
| 161 | next.into_search_bytestringrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_search_bytestring().(bytestring) |
| 162 | } |
| 163 | |
| 164 | /// Search for Dict Entries that have the given key. |
| 165 | /// |
| 166 | /// MUST be followed by a call to one of: [`.key`][PathBuilder::key], |
| 167 | /// [`.into_key`][PathBuilder::into_key], [`.value`][PathBuilder::value], |
| 168 | /// or [`.into_value`][PathBuilder::into_value]. |
| 169 | pub fn into_search_entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_search_entry().(mut self, dict_key: &'step [u8]) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 170 | self.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps..pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#::Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Search#(Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#::DictKeyrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#DictKey#(dict_key))); |
| 171 | self |
| 172 | } |
| 173 | |
| 174 | /// Search for Dict Entries that have the given key. |
| 175 | /// |
| 176 | /// MUST be followed by a call to one of: [`.key`][PathBuilder::key], |
| 177 | /// [`.into_key`][PathBuilder::into_key], [`.value`][PathBuilder::value], |
| 178 | /// or [`.into_value`][PathBuilder::into_value]. |
| 179 | pub fn search_entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]search_entry().(&'obj self, dict_key: &'step [u8]) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 180 | let next = self.clonerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'a>`][Clone]clone().(); |
| 181 | next.into_search_entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_search_entry().(dict_key) |
| 182 | } |
| 183 | |
| 184 | /// Search for an integer, provided as a string slice. |
| 185 | pub fn into_search_intrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_search_int().(mut self, number: &'step str) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 186 | self.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps..pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#::Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Search#(Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#::Intrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#Int#(number.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))); |
| 187 | self |
| 188 | } |
| 189 | |
| 190 | /// Search for an integer, provided as a string slice. |
| 191 | pub fn search_intrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]search_int().(&'obj self, number: &'step str) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 192 | let next = self.clonerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'a>`][Clone]clone().(); |
| 193 | next.into_search_intrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_search_int().(number) |
| 194 | } |
| 195 | |
| 196 | /// Search for an integer, this function converts an i64 to a string slice for you. |
| 197 | pub fn into_search_int_i64rust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_search_int_i64().(mut self, number: i64) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 198 | self.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps. |
| 199 | .pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(Steprust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#::Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Step#Search#(Searchrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#::Intrust-analyzer cargo bendy 0.6.1 inspect/traverse/Search#Int#(number.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))); |
| 200 | self |
| 201 | } |
| 202 | |
| 203 | /// Search for an integer, this function converts an i64 to a string slice for you. |
| 204 | pub fn search_int_i64rust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]search_int_i64().(&'obj self, number: i64) -> PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb> { |
| 205 | let next = self.clonerust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'a>`][Clone]clone().(); |
| 206 | next.into_search_int_i64rust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`PathBuilder<'pb>`]into_search_int_i64().(number) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | impl<'obj, 'ser, 'pb, 'pbobj> Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#<'ser> { |
| 211 | /// Gets a mutable reference to the Inspectable pointed to by the given path. |
| 212 | /// Panics if no Inspectable matches the given path. |
| 213 | pub fn findrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]find().(&'obj mut self, path: &'pbobj PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb>) -> &'obj mut Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#<'ser> { |
| 214 | let res = self.find_implrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]find_impl().(&path.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps., 0); |
| 215 | match res { |
| 216 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Path did not resolve to an Inspectable: {:?}", path), |
| 217 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => x, |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /// Gets a reference to the Inspectable pointed to by the given path. |
| 222 | /// Panics if no Inspectable matches the given path. |
| 223 | pub fn find_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]find_ref().(&'obj self, path: &'pbobj PathBuilderrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#<'pb>) -> &'obj Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#<'ser> { |
| 224 | let res = self.find_ref_implrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]find_ref_impl().(&path.stepsrust-analyzer cargo bendy 0.6.1 inspect/traverse/PathBuilder#steps., 0); |
| 225 | match res { |
| 226 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Path did not resolve to an Inspectable: {:?}", path), |
| 227 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => x, |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | macro_rules! findersrust-analyzer cargo bendy 0.6.1 inspect/traverse/finders! { |
| 233 | ($(($name:ident, $get:ident, $iter:ident, $( $mutable:ident )? ))*) => {$( |
| 234 | impl<'obj, 'ser, 'pb, 'pbobj> Inspectable<'ser> { |
| 235 | fn $name( |
| 236 | &'obj $($mutable)? self, |
| 237 | steps: &'pbobj Path<'pb>, |
| 238 | pc: usize, |
| 239 | ) -> Option<&'obj $($mutable)? Inspectable<'ser>> { |
| 240 | let current_step = if let Some(x) = steps.get(pc) { |
| 241 | x |
| 242 | } else { |
| 243 | return Some(self); |
| 244 | }; |
| 245 | |
| 246 | let descend_into_entry = |
| 247 | |entry: &'obj $($mutable)? InDictEntry<'ser>| -> Option<&'obj $($mutable)? Inspectable<'ser>> { |
| 248 | match steps.get(pc + 1) { |
| 249 | Some(Step::Key) => entry.key.$name(steps, pc + 2), |
| 250 | Some(Step::Value) => entry.value.$name(steps, pc + 2), |
| 251 | _ => panic!( |
| 252 | "A path that selects a dict entry must then select either its key or its value" |
| 253 | ), |
| 254 | } |
| 255 | }; |
| 256 | |
| 257 | match (self, current_step) { |
| 258 | (Inspectable::Raw(_), _) => (), |
| 259 | |
| 260 | (s @ Inspectable::Int(_), Step::Search(Search::Int(x))) => { |
| 261 | if *x == &*s.int_ref().bytes { |
| 262 | return Some(s); |
| 263 | } |
| 264 | }, |
| 265 | (Inspectable::Int(_), _) => (), |
| 266 | |
| 267 | (s @ Inspectable::String(_), Step::Search(Search::ByteString(x))) => { |
| 268 | if *x == &*s.string_ref().bytes { |
| 269 | return Some(s); |
| 270 | } |
| 271 | }, |
| 272 | (Inspectable::String(_), Step::Search(_)) => (), |
| 273 | (Inspectable::String(_), _) => (), |
| 274 | |
| 275 | (Inspectable::List(_), Step::Key) => (), |
| 276 | (Inspectable::List(_), Step::Value) => (), |
| 277 | (Inspectable::List(_), Step::Entry(_)) => (), |
| 278 | (Inspectable::List(in_list), Step::Nth(idx)) => { |
| 279 | let item = in_list.items.$get(*idx)?; |
| 280 | return item.$name(steps, pc + 1); |
| 281 | }, |
| 282 | (Inspectable::List(in_list), Step::Search(_)) => { |
| 283 | return in_list |
| 284 | .items |
| 285 | .$iter() |
| 286 | .find_map(|item| item.$name(steps, pc)); |
| 287 | }, |
| 288 | |
| 289 | (Inspectable::Dict(_), Step::Key) => (), |
| 290 | (Inspectable::Dict(_), Step::Value) => (), |
| 291 | (Inspectable::Dict(in_dict), Step::Nth(idx)) => { |
| 292 | let entry = in_dict.items.$get(*idx)?; |
| 293 | return descend_into_entry(entry); |
| 294 | }, |
| 295 | (Inspectable::Dict(in_dict), Step::Entry(key)) => { |
| 296 | let entry = in_dict.items.$iter().find(|entry| { |
| 297 | let entry_key = if let Inspectable::String(x) = &entry.key { |
| 298 | x |
| 299 | } else { |
| 300 | return false; |
| 301 | }; |
| 302 | entry_key.bytes == *key |
| 303 | })?; |
| 304 | return descend_into_entry(entry); |
| 305 | }, |
| 306 | (Inspectable::Dict(in_dict), Step::Search(Search::DictKey(key))) => { |
| 307 | return in_dict.items.$iter().find_map(|entry| { |
| 308 | if let Inspectable::String(x) = &entry.key { |
| 309 | if x.bytes == *key { |
| 310 | return descend_into_entry(entry); |
| 311 | } |
| 312 | } |
| 313 | entry.value.$name(steps, pc) |
| 314 | }); |
| 315 | }, |
| 316 | (Inspectable::Dict(in_dict), Step::Search(_)) => { |
| 317 | return in_dict |
| 318 | .items |
| 319 | .$iter() |
| 320 | .find_map(|InDictEntry { value, .. }| value.$name(steps, pc)); |
| 321 | }, |
| 322 | }; |
| 323 | None |
| 324 | } |
| 325 | } |
| 326 | )*}; |
| 327 | } |
| 328 | |
| 329 | findersrust-analyzer cargo bendy 0.6.1 inspect/traverse/finders!!( |
| 330 | (find_implrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]find_impl()., get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut()., iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut()., mut) |
| 331 | (find_ref_implrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]find_ref_impl()., getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get()., iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().,) |
| 332 | ); |
| 333 | |
| 334 | macro_rules! variant_accessorsrust-analyzer cargo bendy 0.6.1 inspect/traverse/variant_accessors! { |
| 335 | ($(($name:ident, $mutname:ident, $source:ident, $target:ty, $targettype:ty))*) => {$( |
| 336 | impl<'obj, 'ser> Inspectable<'ser> { |
| 337 | #[doc=concat!("Coercion to immutable reference to [`", stringify!($targettype), "`]. Panics on failure.")] |
| 338 | pub fn $name(&'obj self) -> &'obj $target { |
| 339 | match self { |
| 340 | Inspectable::$source(x) => x, |
| 341 | _ => panic!("Attempted to take non-{} Inspectable as {}", stringify!($source), stringify!($target)) |
| 342 | } |
| 343 | } |
| 344 | #[doc=concat!("Coercion to mutable reference to [`", stringify!($targettype), "`]. Panics on failure.")] |
| 345 | pub fn $mutname(&'obj mut self) -> &'obj mut $target { |
| 346 | match self { |
| 347 | Inspectable::$source(x) => x, |
| 348 | _ => panic!("Attempted to take non-{} Inspectable as mut_{}", stringify!($source), stringify!($target)) |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | )*}; |
| 353 | } |
| 354 | |
| 355 | variant_accessorsrust-analyzer cargo bendy 0.6.1 inspect/traverse/variant_accessors!! { |
| 356 | (string_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]string_ref()., stringrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]string()., Stringrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#String#, InStringrust-analyzer cargo bendy 0.6.1 inspect/InString#<'ser>, InString) |
| 357 | (int_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]int_ref()., intrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]int()., Intrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Int#, InIntrust-analyzer cargo bendy 0.6.1 inspect/InInt#<'ser>, InInt) |
| 358 | (raw_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]raw_ref()., rawrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]raw()., Rawrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Raw#, Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'ser, [u8]>, [u8]) |
| 359 | (dict_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]dict_ref()., dictrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]dict()., Dictrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Dict#, InDictrust-analyzer cargo bendy 0.6.1 inspect/InDict#<'ser>, InDict) |
| 360 | (list_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]list_ref()., listrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]list()., Listrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#List#, InListrust-analyzer cargo bendy 0.6.1 inspect/InList#<'ser>, InList) |
| 361 | } |
| 362 | |
| 363 | impl<'obj, 'ser> InListrust-analyzer cargo bendy 0.6.1 inspect/InList#<'ser> { |
| 364 | pub fn nth_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`InList<'ser>`]nth_ref().(&'obj self, idx: usize) -> &'obj Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#<'ser> { |
| 365 | self.itemsrust-analyzer cargo bendy 0.6.1 inspect/InList#items. |
| 366 | .getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(idx) |
| 367 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Could not access nth Inspectable in list") |
| 368 | } |
| 369 | |
| 370 | pub fn nthrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`InList<'ser>`]nth().(&'obj mut self, idx: usize) -> &'obj mut Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#<'ser> { |
| 371 | self.itemsrust-analyzer cargo bendy 0.6.1 inspect/InList#items. |
| 372 | .get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(idx) |
| 373 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Could not mutably access nth Inspectable in list") |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | impl<'obj, 'ser> InDictrust-analyzer cargo bendy 0.6.1 inspect/InDict#<'ser> { |
| 378 | pub fn nth_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`InDict<'ser>`]nth_ref().(&'obj self, idx: usize) -> &'obj InDictEntryrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#<'ser> { |
| 379 | self.itemsrust-analyzer cargo bendy 0.6.1 inspect/InDict#items. |
| 380 | .getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(idx) |
| 381 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Could not access nth Inspectable in list") |
| 382 | } |
| 383 | |
| 384 | pub fn nthrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`InDict<'ser>`]nth().(&'obj mut self, idx: usize) -> &'obj mut InDictEntryrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#<'ser> { |
| 385 | self.itemsrust-analyzer cargo bendy 0.6.1 inspect/InDict#items. |
| 386 | .get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(idx) |
| 387 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Could not mutably access nth Inspectable in list") |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | impl<'obj, 'ser, 'other> InDictrust-analyzer cargo bendy 0.6.1 inspect/InDict#<'ser> { |
| 392 | pub fn entry_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`InDict<'ser>`]entry_ref().(&'obj self, name: &'other [u8]) -> &'obj InDictEntryrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#<'ser> { |
| 393 | self.itemsrust-analyzer cargo bendy 0.6.1 inspect/InDict#items. |
| 394 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 395 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|InDictEntryrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry# { keyrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#key., .. }| key.string_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]string_ref().().bytesrust-analyzer cargo bendy 0.6.1 inspect/InString#bytes. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Cow<'_, [T]>`][`PartialEq<&[U]>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Cow<'_, [T]>`][`PartialEq<&[U]>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Cow<'_, [T]>`][`PartialEq<&[U]>`]eq().name) |
| 396 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Could not find a Dict Entry with requested key") |
| 397 | } |
| 398 | |
| 399 | pub fn entryrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`InDict<'ser>`]entry().(&'obj mut self, name: &'other [u8]) -> &'obj mut InDictEntryrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#<'ser> { |
| 400 | self.itemsrust-analyzer cargo bendy 0.6.1 inspect/InDict#items. |
| 401 | .iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() |
| 402 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]find().(|InDictEntryrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry# { keyrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#key., .. }| key.string_refrust-analyzer cargo bendy 0.6.1 inspect/traverse/impl#[`Inspectable<'ser>`]string_ref().().bytesrust-analyzer cargo bendy 0.6.1 inspect/InString#bytes. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Cow<'_, [T]>`][`PartialEq<&[U]>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Cow<'_, [T]>`][`PartialEq<&[U]>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Cow<'_, [T]>`][`PartialEq<&[U]>`]eq().name) |
| 403 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Could not find a Dict Entry with requested key") |
| 404 | } |
| 405 | } |