| 1 | use superrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/::*; |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#, IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#}; |
| 4 | |
| 5 | /** |
| 6 | This is a map from fields to some value. |
| 7 | |
| 8 | If you put this in a type,and use Default to initialize it, |
| 9 | you must remember to replace the `FieldMap` using either `FieldMap::defaulted` or `FieldMap::with` |
| 10 | |
| 11 | */ |
| 12 | #[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:)] |
| 13 | pub struct FieldMaprust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#<T> { |
| 14 | // The outer vec is the enum variant (if it's a struct/union it's a single element Vec), |
| 15 | // the inner one is the field within a variant/struct/union. |
| 16 | fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#fields.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>>, |
| 17 | } |
| 18 | |
| 19 | impl<T> FieldMaprust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#<T> { |
| 20 | /// Constructs an FieldMap which maps each field in the DataStructure to a value |
| 21 | /// (obtained by mapping each individual field to `T` using a closure). |
| 22 | pub fn withrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`]with().<'a, F>(ds: &'a DataStructurerust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/DataStructure#<'a>, mut f: F) -> Selfrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`] |
| 23 | where |
| 24 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&'a Fieldrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/Field#<'a>) -> T, |
| 25 | { |
| 26 | Selfrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`] { |
| 27 | fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#fields.: ds |
| 28 | .variantsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/DataStructure#variants. |
| 29 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 30 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|vari| vari.fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/Struct#fields..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(&mut f).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 31 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | #[allow(dead_code)] |
| 36 | pub fn iterrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`]iter().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (FieldIndexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#, &'_ T)> + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + '_ { |
| 37 | self.fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#fields..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|(v_i, v)| { |
| 38 | v.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(move |(f_i, f)| { |
| 39 | let index = FieldIndexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex# { |
| 40 | variantrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#variant.: v_i as _, |
| 41 | posrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#pos.: f_i as _, |
| 42 | }; |
| 43 | (index, f) |
| 44 | }) |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | #[allow(dead_code)] |
| 49 | pub fn iter_mutrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`]iter_mut().(&mut self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (FieldIndexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#, &'_ mut T)> + '_ { |
| 50 | self.fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#fields..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|(v_i, v)| { |
| 51 | v.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(move |(f_i, f)| { |
| 52 | let index = FieldIndexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex# { |
| 53 | variantrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#variant.: v_i as _, |
| 54 | posrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#pos.: f_i as _, |
| 55 | }; |
| 56 | (index, f) |
| 57 | }) |
| 58 | }) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | impl<'a, T> Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<FieldIndexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#> for FieldMaprust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#<T> { |
| 63 | type Outputrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`][`Index<FieldIndex>`]Output# = T; |
| 64 | |
| 65 | fn indexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`][`Index<FieldIndex>`]index().(&self, index: FieldIndexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#) -> &T { |
| 66 | &self.fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#fields.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index.variantrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#variant.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index.posrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#pos.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | impl<'a, T> IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<FieldIndexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#> for FieldMaprust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#<T> { |
| 71 | fn index_mutrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`][`IndexMut<FieldIndex>`]index_mut().(&mut self, index: FieldIndexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#) -> &mut T { |
| 72 | &mut self.fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#fields.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().index.variantrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#variant.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().index.posrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#pos.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | impl<'a, T> Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<&'a Fieldrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/Field#<'a>> for FieldMaprust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#<T> { |
| 77 | type Outputrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`][`Index<&'a Field<'a>>`]Output# = T; |
| 78 | |
| 79 | fn indexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`][`Index<&'a Field<'a>>`]index().(&self, field: &'a Fieldrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/Field#<'a>) -> &T { |
| 80 | let index = field.indexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/Field#index.; |
| 81 | &self.fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#fields.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index.variantrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#variant.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index.posrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#pos.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | impl<'a, T> IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<&'a Fieldrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/Field#<'a>> for FieldMaprust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#<T> { |
| 86 | fn index_mutrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/impl#[`FieldMap<T>`][`IndexMut<&'a Field<'a>>`]index_mut().(&mut self, field: &'a Fieldrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/Field#<'a>) -> &mut T { |
| 87 | let index = field.indexrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/Field#index.; |
| 88 | &mut self.fieldsrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/field_map/FieldMap#fields.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().index.variantrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#variant.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().index.posrust-analyzer cargo const_format_proc_macros 0.2.34 datastructure/FieldIndex#pos.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 89 | } |
| 90 | } |