1- use anyerror:: AnyError ;
21use std:: collections:: HashMap ;
2+
3+ #[ cfg( feature = "serde" ) ]
34use std:: fmt:: Debug ;
45
56#[ cfg( feature = "serde" ) ]
@@ -15,6 +16,15 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
1516///////////////////////
1617/// IdentifiedVecOf ///
1718///////////////////////
19+
20+ /// A type alias for `IdentifiedVec<Element::ID, Element>`, this is the
21+ /// preferred and most powerful collection type of this crate, requires
22+ /// that your `Element`s impl the `Identifiable` trait. Using this collection
23+ /// allows you to skip passing the `id_of_element: fn(&Element) -> ID` closure
24+ /// which you otherwise need to pass when initializing an `IdentifiedVec`. Using
25+ /// `IdentifiedVecOf` together with feature "serde" also gives serde
26+ /// serialization/deserialization as if it were a `Vec<Element>`, given that
27+ /// `Element` implements serde serialization/deserialization of course.
1828pub type IdentifiedVecOf < Element > = IdentifiedVec < <Element as Identifiable >:: ID , Element > ;
1929
2030//////////////////////////////////////////////
@@ -73,14 +83,14 @@ where
7383 /// - Complexity: Expected O(*n*) on average, where *n* is the count of elements, if `ID`
7484 /// implements high-quality hashing.
7585 #[ inline]
76- pub fn new_from_iter_try_uniquing_with < I > (
86+ pub fn try_from_iter_select_unique_with < E , I > (
7787 elements : I ,
78- combine : fn ( ( usize , & Element , & Element ) ) -> Result < ConflictResolutionChoice , AnyError > ,
79- ) -> Result < Self , AnyError >
88+ combine : fn ( ( usize , & Element , & Element ) ) -> Result < ConflictResolutionChoice , E > ,
89+ ) -> Result < Self , E >
8090 where
8191 I : IntoIterator < Item = Element > ,
8292 {
83- Self :: new_from_iter_try_uniquing_ids_with ( elements, |e| e. id ( ) , combine)
93+ Self :: try_from_iter_select_unique_ids_with ( elements, |e| e. id ( ) , combine)
8494 }
8595
8696 /// Creates a new `identified_vec` from the elements in the given sequence, using a combining closure to
@@ -99,14 +109,14 @@ where
99109 /// - Complexity: Expected O(*n*) on average, where *n* is the count of elements, if `ID`
100110 /// implements high-quality hashing.
101111 #[ inline]
102- pub fn new_from_iter_uniquing_with < I > (
112+ pub fn from_iter_select_unique_with < I > (
103113 elements : I ,
104114 combine : fn ( ( usize , & Element , & Element ) ) -> ConflictResolutionChoice ,
105115 ) -> Self
106116 where
107117 I : IntoIterator < Item = Element > ,
108118 {
109- Self :: new_from_iter_uniquing_ids_with ( elements, |e| e. id ( ) , combine)
119+ Self :: from_iter_select_unique_ids_with ( elements, |e| e. id ( ) , combine)
110120 }
111121}
112122
@@ -136,10 +146,8 @@ where
136146 deserializer : D ,
137147 ) -> Result < IdentifiedVecOf < Element > , D :: Error > {
138148 let elements = Vec :: < Element > :: deserialize ( deserializer) ?;
139- IdentifiedVecOf :: < Element > :: new_from_iter_try_uniquing_with ( elements, |( idx, _, _) | {
140- Err ( AnyError :: new (
141- & IdentifiedVecOfSerdeFailure :: DuplicateElementsAtIndex ( idx) ,
142- ) )
149+ IdentifiedVecOf :: < Element > :: try_from_iter_select_unique_with ( elements, |( idx, _, _) | {
150+ Err ( IdentifiedVecOfSerdeFailure :: DuplicateElementsAtIndex ( idx) )
143151 } )
144152 . map_err ( de:: Error :: custom)
145153 }
0 commit comments