| 1 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#; |
| 2 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/; |
| 3 | use indexmaprust-analyzer cargo indexmap 2.14.0 crate/::maprust-analyzer cargo indexmap 2.14.0 map/ as ixrust-analyzer cargo indexmap 2.14.0 map/; |
| 4 | |
| 5 | #[cfg(doc)] |
| 6 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 7 | |
| 8 | /// Entry for an existing key-value pair in an [`OrderMap`][crate::OrderMap] |
| 9 | /// or a vacant location to insert one. |
| 10 | pub enum Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#<'a, K, V> { |
| 11 | /// Existing slot with equivalent key. |
| 12 | Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V>), |
| 13 | /// Vacant slot (no equivalent key in the map). |
| 14 | Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(VacantEntryrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#<'a, K, V>), |
| 15 | } |
| 16 | |
| 17 | impl<'a, K, V> Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#<'a, K, V> { |
| 18 | pub(superrust-analyzer cargo ordermap 1.2.0 map/) fn newrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]new().(entry: ixrust-analyzer cargo indexmap 2.14.0 map/::Entryrust-analyzer cargo indexmap 2.14.0 map/entry/Entry#<'a, K, V>) -> Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`] { |
| 19 | match entry { |
| 20 | ixrust-analyzer cargo indexmap 2.14.0 map/::Entryrust-analyzer cargo indexmap 2.14.0 map/entry/Entry#::Occupiedrust-analyzer cargo indexmap 2.14.0 map/entry/Entry#Occupied#(inner) => Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry# { innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner. }), |
| 21 | ixrust-analyzer cargo indexmap 2.14.0 map/::Entryrust-analyzer cargo indexmap 2.14.0 map/entry/Entry#::Vacantrust-analyzer cargo indexmap 2.14.0 map/entry/Entry#Vacant#(inner) => Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(VacantEntryrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry# { innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner. }), |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /// Return the index where the key-value pair exists or will be inserted. |
| 26 | pub fn indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]index().(&self) -> usize { |
| 27 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 28 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(ref entry) => entry.indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]index().(), |
| 29 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(ref entry) => entry.indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]index().(), |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /// Sets the value of the entry (after inserting if vacant), and returns an `OccupiedEntry`. |
| 34 | /// |
| 35 | /// Computes in **O(1)** time (amortized average). |
| 36 | pub fn insert_entryrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]insert_entry().(self, value: V) -> OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V> { |
| 37 | match self { |
| 38 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(mut entry) => { |
| 39 | entry.insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]insert().(value); |
| 40 | entry |
| 41 | } |
| 42 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(entry) => entry.insert_entryrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert_entry().(value), |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /// Inserts the given default value in the entry if it is vacant and returns a mutable |
| 47 | /// reference to it. Otherwise a mutable reference to an already existent value is returned. |
| 48 | /// |
| 49 | /// Computes in **O(1)** time (amortized average). |
| 50 | pub fn or_insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert().(self, default: V) -> &'a mut V { |
| 51 | match self { |
| 52 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(entry) => entry.into_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]into_mut().(), |
| 53 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(entry) => entry.insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert().(default), |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /// Inserts the result of the `call` function in the entry if it is vacant and returns a mutable |
| 58 | /// reference to it. Otherwise a mutable reference to an already existent value is returned. |
| 59 | /// |
| 60 | /// Computes in **O(1)** time (amortized average). |
| 61 | pub fn or_insert_withrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert_with().<F>(self, call: F) -> &'a mut V |
| 62 | where |
| 63 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> V, |
| 64 | { |
| 65 | match self { |
| 66 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(entry) => entry.into_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]into_mut().(), |
| 67 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(entry) => entry.insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert().(call()), |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /// Inserts the result of the `call` function with a reference to the entry's key if it is |
| 72 | /// vacant, and returns a mutable reference to the new value. Otherwise a mutable reference to |
| 73 | /// an already existent value is returned. |
| 74 | /// |
| 75 | /// Computes in **O(1)** time (amortized average). |
| 76 | pub fn or_insert_with_keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert_with_key().<F>(self, call: F) -> &'a mut V |
| 77 | where |
| 78 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&K) -> V, |
| 79 | { |
| 80 | match self { |
| 81 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(entry) => entry.into_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]into_mut().(), |
| 82 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(entry) => { |
| 83 | let value = call(&entry.keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]key().()); |
| 84 | entry.insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert().(value) |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /// Gets a reference to the entry's key, either within the map if occupied, |
| 90 | /// or else the new key that was used to find the entry. |
| 91 | pub fn keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]key().(&self) -> &K { |
| 92 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 93 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(ref entry) => entry.keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]key().(), |
| 94 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(ref entry) => entry.keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]key().(), |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /// Modifies the entry if it is occupied. |
| 99 | pub fn and_modifyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]and_modify().<F>(mut self, f: F) -> Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`] |
| 100 | where |
| 101 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&mut V), |
| 102 | { |
| 103 | if let Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(entry) = &mut self { |
| 104 | f(entry.get_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]get_mut().()); |
| 105 | } |
| 106 | self |
| 107 | } |
| 108 | |
| 109 | /// Inserts a default-constructed value in the entry if it is vacant and returns a mutable |
| 110 | /// reference to it. Otherwise a mutable reference to an already existent value is returned. |
| 111 | /// |
| 112 | /// Computes in **O(1)** time (amortized average). |
| 113 | pub fn or_defaultrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'a, K, V>`]or_default().(self) -> &'a mut V |
| 114 | where |
| 115 | V: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, |
| 116 | { |
| 117 | match self { |
| 118 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(entry) => entry.into_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]into_mut().(), |
| 119 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(entry) => entry.insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert().(V::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().()), |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | impl<K: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, V: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#<'_, K, V> { |
| 125 | fn fmtrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`Entry<'_, K, V>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 126 | let mut tuple = f.debug_tuplerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_tuple().("Entry"); |
| 127 | match self { |
| 128 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Vacantrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Vacant#(v) => tuple.fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(v), |
| 129 | Entryrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#::Occupiedrust-analyzer cargo ordermap 1.2.0 map/entry/Entry#Occupied#(o) => tuple.fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(o), |
| 130 | }; |
| 131 | tuple.finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]finish().() |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /// A view into an occupied entry in an [`OrderMap`][crate::OrderMap]. |
| 136 | /// It is part of the [`Entry`] enum. |
| 137 | pub struct OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V> { |
| 138 | pub(craterust-analyzer cargo ordermap 1.2.0 crate/) innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner.: ixrust-analyzer cargo indexmap 2.14.0 map/::OccupiedEntryrust-analyzer cargo indexmap 2.14.0 inner/entry/OccupiedEntry#<'a, K, V>, |
| 139 | } |
| 140 | |
| 141 | impl<'a, K, V> OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V> { |
| 142 | /// Return the index of the key-value pair |
| 143 | #[inline] |
| 144 | pub fn indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]index().(&self) -> usize { |
| 145 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..indexrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]index().() |
| 146 | } |
| 147 | |
| 148 | /// Gets a reference to the entry's key in the map. |
| 149 | /// |
| 150 | /// Note that this is not the key that was used to find the entry. There may be an observable |
| 151 | /// difference if the key type has any distinguishing features outside of `Hash` and `Eq`, like |
| 152 | /// extra fields or the memory address of an allocation. |
| 153 | pub fn keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]key().(&self) -> &K { |
| 154 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..keyrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]key().() |
| 155 | } |
| 156 | |
| 157 | /// Gets a reference to the entry's value in the map. |
| 158 | pub fn getrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]get().(&self) -> &V { |
| 159 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..getrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]get().() |
| 160 | } |
| 161 | |
| 162 | /// Gets a mutable reference to the entry's value in the map. |
| 163 | /// |
| 164 | /// If you need a reference which may outlive the destruction of the |
| 165 | /// [`Entry`] value, see [`into_mut`][Self::into_mut]. |
| 166 | pub fn get_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]get_mut().(&mut self) -> &mut V { |
| 167 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..get_mutrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]get_mut().() |
| 168 | } |
| 169 | |
| 170 | /// Converts into a mutable reference to the entry's value in the map, |
| 171 | /// with a lifetime bound to the map itself. |
| 172 | pub fn into_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]into_mut().(self) -> &'a mut V { |
| 173 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..into_mutrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]into_mut().() |
| 174 | } |
| 175 | |
| 176 | /// Sets the value of the entry to `value`, and returns the entry's old value. |
| 177 | pub fn insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]insert().(&mut self, value: V) -> V { |
| 178 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..insertrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]insert().(value) |
| 179 | } |
| 180 | |
| 181 | /// Remove the key, value pair stored in the map for this entry, and return the value. |
| 182 | /// |
| 183 | /// **NOTE:** This is equivalent to indexmap's |
| 184 | /// [`OccupiedEntry::shift_remove`][ix::OccupiedEntry::shift_remove], and |
| 185 | /// like [`Vec::remove`], the pair is removed by shifting all of the |
| 186 | /// elements that follow it, preserving their relative order. |
| 187 | /// **This perturbs the index of all of those elements!** |
| 188 | /// |
| 189 | /// Computes in **O(n)** time (average). |
| 190 | pub fn removerust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]remove().(self) -> V { |
| 191 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..shift_removerust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]shift_remove().() |
| 192 | } |
| 193 | |
| 194 | /// Remove and return the key, value pair stored in the map for this entry |
| 195 | /// |
| 196 | /// **NOTE:** This is equivalent to indexmap's |
| 197 | /// [`OccupiedEntry::shift_remove_entry`][ix::OccupiedEntry::shift_remove_entry], and |
| 198 | /// like [`Vec::remove`], the pair is removed by shifting all of the |
| 199 | /// elements that follow it, preserving their relative order. |
| 200 | /// **This perturbs the index of all of those elements!** |
| 201 | /// |
| 202 | /// Computes in **O(n)** time (average). |
| 203 | pub fn remove_entryrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]remove_entry().(self) -> (K, V) { |
| 204 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..shift_remove_entryrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]shift_remove_entry().() |
| 205 | } |
| 206 | |
| 207 | /// Remove the key, value pair stored in the map for this entry, and return the value. |
| 208 | /// |
| 209 | /// Like [`Vec::swap_remove`], the pair is removed by swapping it with |
| 210 | /// the last element of the map and popping it off. |
| 211 | /// **This perturbs the position of what used to be the last element!** |
| 212 | /// |
| 213 | /// Computes in **O(1)** time (average). |
| 214 | pub fn swap_removerust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]swap_remove().(self) -> V { |
| 215 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..swap_removerust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]swap_remove().() |
| 216 | } |
| 217 | |
| 218 | /// Remove and return the key, value pair stored in the map for this entry |
| 219 | /// |
| 220 | /// Like [`Vec::swap_remove`], the pair is removed by swapping it with |
| 221 | /// the last element of the map and popping it off. |
| 222 | /// **This perturbs the position of what used to be the last element!** |
| 223 | /// |
| 224 | /// Computes in **O(1)** time (average). |
| 225 | pub fn swap_remove_entryrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]swap_remove_entry().(self) -> (K, V) { |
| 226 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..swap_remove_entryrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]swap_remove_entry().() |
| 227 | } |
| 228 | |
| 229 | /// Moves the position of the entry to a new index |
| 230 | /// by shifting all other entries in-between. |
| 231 | /// |
| 232 | /// This is equivalent to [`OrderMap::move_index`][`crate::OrderMap::move_index`] |
| 233 | /// coming `from` the current [`.index()`][Self::index]. |
| 234 | /// |
| 235 | /// * If `self.index() < to`, the other pairs will shift down while the targeted pair moves up. |
| 236 | /// * If `self.index() > to`, the other pairs will shift up while the targeted pair moves down. |
| 237 | /// |
| 238 | /// ***Panics*** if `to` is out of bounds. |
| 239 | /// |
| 240 | /// Computes in **O(n)** time (average). |
| 241 | #[track_caller] |
| 242 | pub fn move_indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]move_index().(self, to: usize) { |
| 243 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..move_indexrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]move_index().(to); |
| 244 | } |
| 245 | |
| 246 | /// Swaps the position of entry with another. |
| 247 | /// |
| 248 | /// This is equivalent to [`OrderMap::swap_indices`][`crate::OrderMap::swap_indices`] |
| 249 | /// with the current [`.index()`][Self::index] as one of the two being swapped. |
| 250 | /// |
| 251 | /// ***Panics*** if the `other` index is out of bounds. |
| 252 | /// |
| 253 | /// Computes in **O(1)** time (average). |
| 254 | #[track_caller] |
| 255 | pub fn swap_indicesrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]swap_indices().(self, other: usize) { |
| 256 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..swap_indicesrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`OccupiedEntry<'a, K, V>`]swap_indices().(other); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | impl<K: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, V: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'_, K, V> { |
| 261 | fn fmtrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'_, K, V>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 262 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("OccupiedEntry") |
| 263 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("key", self.keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]key().()) |
| 264 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("value", self.getrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`]get().()) |
| 265 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | impl<'a, K, V> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<IndexedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#<'a, K, V>> for OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V> { |
| 270 | fn fromrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`][`From<IndexedEntry<'a, K, V>>`]from().(entry: IndexedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#<'a, K, V>) -> Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`][`From<IndexedEntry<'a, K, V>>`] { |
| 271 | Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`OccupiedEntry<'a, K, V>`][`From<IndexedEntry<'a, K, V>>`] { |
| 272 | innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner.: entry.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /// A view into a vacant entry in an [`OrderMap`][crate::OrderMap]. |
| 278 | /// It is part of the [`Entry`] enum. |
| 279 | pub struct VacantEntryrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#<'a, K, V> { |
| 280 | pub(craterust-analyzer cargo ordermap 1.2.0 crate/) innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner.: ixrust-analyzer cargo indexmap 2.14.0 map/::VacantEntryrust-analyzer cargo indexmap 2.14.0 inner/entry/VacantEntry#<'a, K, V>, |
| 281 | } |
| 282 | |
| 283 | impl<'a, K, V> VacantEntryrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#<'a, K, V> { |
| 284 | /// Return the index where a key-value pair may be inserted. |
| 285 | pub fn indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]index().(&self) -> usize { |
| 286 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..indexrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]index().() |
| 287 | } |
| 288 | |
| 289 | /// Gets a reference to the key that was used to find the entry. |
| 290 | pub fn keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]key().(&self) -> &K { |
| 291 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..keyrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]key().() |
| 292 | } |
| 293 | |
| 294 | /// Takes ownership of the key, leaving the entry vacant. |
| 295 | pub fn into_keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]into_key().(self) -> K { |
| 296 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..into_keyrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]into_key().() |
| 297 | } |
| 298 | |
| 299 | /// Inserts the entry's key and the given value into the map, and returns a mutable reference |
| 300 | /// to the value. |
| 301 | pub fn insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert().(self, value: V) -> &'a mut V { |
| 302 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..insertrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]insert().(value) |
| 303 | } |
| 304 | |
| 305 | /// Inserts the entry's key and the given value into the map, and returns an `OccupiedEntry`. |
| 306 | /// |
| 307 | /// Computes in **O(1)** time (amortized average). |
| 308 | pub fn insert_entryrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert_entry().(self, value: V) -> OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V> { |
| 309 | OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry# { |
| 310 | innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner.: self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..insert_entryrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]insert_entry().(value), |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | /// Inserts the entry's key and the given value into the map at its ordered |
| 315 | /// position among sorted keys, and returns the new index and a mutable |
| 316 | /// reference to the value. |
| 317 | /// |
| 318 | /// If the existing keys are **not** already sorted, then the insertion |
| 319 | /// index is unspecified (like [`slice::binary_search`]), but the key-value |
| 320 | /// pair is inserted at that position regardless. |
| 321 | /// |
| 322 | /// Computes in **O(n)** time (average). |
| 323 | pub fn insert_sortedrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert_sorted().(self, value: V) -> (usize, &'a mut V) |
| 324 | where |
| 325 | K: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#, |
| 326 | { |
| 327 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..insert_sortedrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]insert_sorted().(value) |
| 328 | } |
| 329 | |
| 330 | /// Inserts the entry's key and the given value into the map at its ordered |
| 331 | /// position among keys sorted by `cmp`, and returns the new index and a |
| 332 | /// mutable reference to the value. |
| 333 | /// |
| 334 | /// If the existing keys are **not** already sorted, then the insertion |
| 335 | /// index is unspecified (like [`slice::binary_search`]), but the key-value |
| 336 | /// pair is inserted at that position regardless. |
| 337 | /// |
| 338 | /// Computes in **O(n)** time (average). |
| 339 | pub fn insert_sorted_byrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert_sorted_by().<F>(self, value: V, cmp: F) -> (usize, &'a mut V) |
| 340 | where |
| 341 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&K, &V, &K, &V) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#, |
| 342 | { |
| 343 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..insert_sorted_byrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]insert_sorted_by().(value, cmp) |
| 344 | } |
| 345 | |
| 346 | /// Inserts the entry's key and the given value into the map at its ordered |
| 347 | /// position using a sort-key extraction function, and returns the new index |
| 348 | /// and a mutable reference to the value. |
| 349 | /// |
| 350 | /// If the existing keys are **not** already sorted, then the insertion |
| 351 | /// index is unspecified (like [`slice::binary_search`]), but the key-value |
| 352 | /// pair is inserted at that position regardless. |
| 353 | /// |
| 354 | /// Computes in **O(n)** time (average). |
| 355 | pub fn insert_sorted_by_keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]insert_sorted_by_key().<B, F>(self, value: V, sort_key: F) -> (usize, &'a mut V) |
| 356 | where |
| 357 | B: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#, |
| 358 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&K, &V) -> B, |
| 359 | { |
| 360 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..insert_sorted_by_keyrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]insert_sorted_by_key().(value, sort_key) |
| 361 | } |
| 362 | |
| 363 | /// Inserts the entry's key and the given value into the map at the given index, |
| 364 | /// shifting others to the right, and returns a mutable reference to the value. |
| 365 | /// |
| 366 | /// ***Panics*** if `index` is out of bounds. |
| 367 | /// |
| 368 | /// Computes in **O(n)** time (average). |
| 369 | #[track_caller] |
| 370 | pub fn shift_insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]shift_insert().(self, index: usize, value: V) -> &'a mut V { |
| 371 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..shift_insertrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]shift_insert().(index, value) |
| 372 | } |
| 373 | |
| 374 | /// Replaces the key at the given index with this entry's key, returning the |
| 375 | /// old key and an `OccupiedEntry` for that index. |
| 376 | /// |
| 377 | /// ***Panics*** if `index` is out of bounds. |
| 378 | /// |
| 379 | /// Computes in **O(1)** time (average). |
| 380 | #[track_caller] |
| 381 | pub fn replace_indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]replace_index().(self, index: usize) -> (K, OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V>) { |
| 382 | let (old_key, inner) = self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#inner..replace_indexrust-analyzer cargo indexmap 2.14.0 inner/entry/impl#[`VacantEntry<'a, K, V>`]replace_index().(index); |
| 383 | (old_key, OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry# { innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner. }) |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | impl<K: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, V> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for VacantEntryrust-analyzer cargo ordermap 1.2.0 map/entry/VacantEntry#<'_, K, V> { |
| 388 | fn fmtrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'_, K, V>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 389 | f.debug_tuplerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_tuple().("VacantEntry").fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(self.keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`VacantEntry<'a, K, V>`]key().()).finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]finish().() |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /// A view into an occupied entry in an [`OrderMap`][crate::OrderMap] obtained by index. |
| 394 | /// |
| 395 | /// This `struct` is created from the [`get_index_entry`][crate::OrderMap::get_index_entry] method. |
| 396 | pub struct IndexedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#<'a, K, V> { |
| 397 | pub(craterust-analyzer cargo ordermap 1.2.0 crate/) innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner.: ixrust-analyzer cargo indexmap 2.14.0 map/::IndexedEntryrust-analyzer cargo indexmap 2.14.0 map/entry/IndexedEntry#<'a, K, V>, |
| 398 | } |
| 399 | |
| 400 | impl<'a, K, V> IndexedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#<'a, K, V> { |
| 401 | pub(superrust-analyzer cargo ordermap 1.2.0 map/) fn newrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]new().(inner: ixrust-analyzer cargo indexmap 2.14.0 map/::IndexedEntryrust-analyzer cargo indexmap 2.14.0 map/entry/IndexedEntry#<'a, K, V>) -> Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`] { |
| 402 | Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`] { innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner. } |
| 403 | } |
| 404 | |
| 405 | /// Return the index of the key-value pair |
| 406 | #[inline] |
| 407 | pub fn indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]index().(&self) -> usize { |
| 408 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..indexrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]index().() |
| 409 | } |
| 410 | |
| 411 | /// Gets a reference to the entry's key in the map. |
| 412 | pub fn keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]key().(&self) -> &K { |
| 413 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..keyrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]key().() |
| 414 | } |
| 415 | |
| 416 | /// Gets a reference to the entry's value in the map. |
| 417 | pub fn getrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]get().(&self) -> &V { |
| 418 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..getrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]get().() |
| 419 | } |
| 420 | |
| 421 | /// Gets a mutable reference to the entry's value in the map. |
| 422 | /// |
| 423 | /// If you need a reference which may outlive the destruction of the |
| 424 | /// `IndexedEntry` value, see [`into_mut`][Self::into_mut]. |
| 425 | pub fn get_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]get_mut().(&mut self) -> &mut V { |
| 426 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..get_mutrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]get_mut().() |
| 427 | } |
| 428 | |
| 429 | /// Sets the value of the entry to `value`, and returns the entry's old value. |
| 430 | pub fn insertrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]insert().(&mut self, value: V) -> V { |
| 431 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..insertrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]insert().(value) |
| 432 | } |
| 433 | |
| 434 | /// Converts into a mutable reference to the entry's value in the map, |
| 435 | /// with a lifetime bound to the map itself. |
| 436 | pub fn into_mutrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]into_mut().(self) -> &'a mut V { |
| 437 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..into_mutrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]into_mut().() |
| 438 | } |
| 439 | |
| 440 | /// Remove and return the key, value pair stored in the map for this entry |
| 441 | /// |
| 442 | /// **NOTE:** This is equivalent to indexmap's |
| 443 | /// [`IndexedEntry::shift_remove_entry`][ix::IndexedEntry::shift_remove_entry], and |
| 444 | /// like [`Vec::remove`], the pair is removed by shifting all of the |
| 445 | /// elements that follow it, preserving their relative order. |
| 446 | /// **This perturbs the index of all of those elements!** |
| 447 | /// |
| 448 | /// Computes in **O(n)** time (average). |
| 449 | pub fn remove_entryrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]remove_entry().(self) -> (K, V) { |
| 450 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..shift_remove_entryrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]shift_remove_entry().() |
| 451 | } |
| 452 | |
| 453 | /// Remove the key, value pair stored in the map for this entry, and return the value. |
| 454 | /// |
| 455 | /// **NOTE:** This is equivalent to indexmap's |
| 456 | /// [`IndexedEntry::shift_remove`][ix::IndexedEntry::shift_remove], and |
| 457 | /// like [`Vec::remove`], the pair is removed by shifting all of the |
| 458 | /// elements that follow it, preserving their relative order. |
| 459 | /// **This perturbs the index of all of those elements!** |
| 460 | /// |
| 461 | /// Computes in **O(n)** time (average). |
| 462 | pub fn removerust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]remove().(self) -> V { |
| 463 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..shift_removerust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]shift_remove().() |
| 464 | } |
| 465 | |
| 466 | /// Remove and return the key, value pair stored in the map for this entry |
| 467 | /// |
| 468 | /// Like [`Vec::swap_remove`], the pair is removed by swapping it with |
| 469 | /// the last element of the map and popping it off. |
| 470 | /// **This perturbs the position of what used to be the last element!** |
| 471 | /// |
| 472 | /// Computes in **O(1)** time (average). |
| 473 | pub fn swap_remove_entryrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]swap_remove_entry().(self) -> (K, V) { |
| 474 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..swap_remove_entryrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]swap_remove_entry().() |
| 475 | } |
| 476 | |
| 477 | /// Remove the key, value pair stored in the map for this entry, and return the value. |
| 478 | /// |
| 479 | /// Like [`Vec::swap_remove`], the pair is removed by swapping it with |
| 480 | /// the last element of the map and popping it off. |
| 481 | /// **This perturbs the position of what used to be the last element!** |
| 482 | /// |
| 483 | /// Computes in **O(1)** time (average). |
| 484 | pub fn swap_removerust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]swap_remove().(self) -> V { |
| 485 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..swap_removerust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]swap_remove().() |
| 486 | } |
| 487 | |
| 488 | /// Moves the position of the entry to a new index |
| 489 | /// by shifting all other entries in-between. |
| 490 | /// |
| 491 | /// This is equivalent to [`OrderMap::move_index`][`crate::OrderMap::move_index`] |
| 492 | /// coming `from` the current [`.index()`][Self::index]. |
| 493 | /// |
| 494 | /// * If `self.index() < to`, the other pairs will shift down while the targeted pair moves up. |
| 495 | /// * If `self.index() > to`, the other pairs will shift up while the targeted pair moves down. |
| 496 | /// |
| 497 | /// ***Panics*** if `to` is out of bounds. |
| 498 | /// |
| 499 | /// Computes in **O(n)** time (average). |
| 500 | #[track_caller] |
| 501 | pub fn move_indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]move_index().(self, to: usize) { |
| 502 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..move_indexrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]move_index().(to) |
| 503 | } |
| 504 | |
| 505 | /// Swaps the position of entry with another. |
| 506 | /// |
| 507 | /// This is equivalent to [`OrderMap::swap_indices`][`crate::OrderMap::swap_indices`] |
| 508 | /// with the current [`.index()`][Self::index] as one of the two being swapped. |
| 509 | /// |
| 510 | /// ***Panics*** if the `other` index is out of bounds. |
| 511 | /// |
| 512 | /// Computes in **O(1)** time (average). |
| 513 | #[track_caller] |
| 514 | pub fn swap_indicesrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]swap_indices().(self, other: usize) { |
| 515 | self.innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner..swap_indicesrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]swap_indices().(other) |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | impl<K: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, V: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for IndexedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#<'_, K, V> { |
| 520 | fn fmtrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'_, K, V>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 521 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("IndexedEntry") |
| 522 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("index", &self.indexrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]index().()) |
| 523 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("key", self.keyrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]key().()) |
| 524 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("value", self.getrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`]get().()) |
| 525 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | impl<'a, K, V> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V>> for IndexedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#<'a, K, V> { |
| 530 | fn fromrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`][`From<OccupiedEntry<'a, K, V>>`]from().(entry: OccupiedEntryrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#<'a, K, V>) -> Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`][`From<OccupiedEntry<'a, K, V>>`] { |
| 531 | Selfrust-analyzer cargo ordermap 1.2.0 map/entry/impl#[`IndexedEntry<'a, K, V>`][`From<OccupiedEntry<'a, K, V>>`] { |
| 532 | innerrust-analyzer cargo ordermap 1.2.0 map/entry/IndexedEntry#inner.: entry.innerrust-analyzer cargo ordermap 1.2.0 map/entry/OccupiedEntry#inner..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 533 | } |
| 534 | } |
| 535 | } |