diff --git a/identified_vec/src/vec.rs b/identified_vec/src/vec.rs index 7d80c9b..9957d02 100644 --- a/identified_vec/src/vec.rs +++ b/identified_vec/src/vec.rs @@ -827,26 +827,6 @@ where } } -/////////////////////// -//// DEBUG /// -/////////////////////// -impl IdentifiedVec -where - E: Debug, - I: Eq + Hash + Clone + Debug, -{ - #[cfg(not(tarpaulin_include))] - #[cfg(debug_assertions)] - pub fn debug(&self) { - println!("{}", self.debug_str()); - } - - #[cfg(debug_assertions)] - pub fn debug_str(&self) -> String { - format!("order: {:?}\nelements: {:?}", self.order, self.elements) - } -} - impl IdentifiedVec where ID: Eq + Hash + Clone + Debug, diff --git a/identified_vec_macros/src/lib.rs b/identified_vec_macros/src/lib.rs index 6d59bc5..aadd296 100644 --- a/identified_vec_macros/src/lib.rs +++ b/identified_vec_macros/src/lib.rs @@ -1,8 +1,6 @@ #[macro_export] macro_rules! newtype_identified_vec { (of: $item_ty: ty, named: $struct_name: ident) => { - use identified_vec::IdentifiedVecIntoIterator; - #[derive(Debug, Clone, Eq, PartialEq)] pub struct $struct_name(IdentifiedVecOf<$item_ty>); @@ -21,9 +19,16 @@ macro_rules! newtype_identified_vec { } } + impl std::fmt::Display for $struct_name { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.elements().fmt(f) + } + } + impl IntoIterator for $struct_name { type Item = $item_ty; - type IntoIter = IdentifiedVecIntoIterator<<$item_ty as Identifiable>::ID, $item_ty>; + type IntoIter = + identified_vec::IdentifiedVecIntoIterator<<$item_ty as Identifiable>::ID, $item_ty>; fn into_iter(self) -> Self::IntoIter { Self::IntoIter::new(self.0) diff --git a/tests/tests.rs b/tests/tests.rs index a4f8c4f..0e02ec1 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -55,7 +55,7 @@ impl Identifiable for User { } } -type SUT = IdentifiedVecOf; +newtype_identified_vec!(of: u32, named: SUT); newtype_identified_vec!(of: User, named: Users); #[test] @@ -69,14 +69,6 @@ fn ids() { assert_eq!(identified_vec.ids(), &[1, 2, 3]) } -#[test] -fn debug_str() { - let identified_vec = SUT::from_iter([1, 2, 3]); - assert!(identified_vec - .debug_str() - .starts_with("order: [1, 2, 3]\nelements: {"),) -} - #[test] fn elements() { let vec = vec![User::blob(), User::blob_jr(), User::blob_sr()]; @@ -306,6 +298,7 @@ fn append() { #[test] fn try_append_unique_element() { + type SUT = IdentifiedVecOf; let mut identified_vec = SUT::from_iter([1, 2, 3]); let result = identified_vec.try_append_unique_element(4); assert!(result.is_ok()); @@ -644,6 +637,7 @@ fn display() { #[test] fn hash() { + type SUT = IdentifiedVecOf; let identified_vec = SUT::from_iter([1, 2, 3]); assert_eq!( HashSet::>::from_iter([identified_vec.clone()]), @@ -651,43 +645,6 @@ fn hash() { ) } -#[test] -fn isid() { - struct CollectionOfUsersVia(IdentifiedVecOf); - impl ViaMarker for CollectionOfUsersVia {} - impl IsIdentifiableVecOfVia for CollectionOfUsersVia { - fn via_mut(&mut self) -> &mut IdentifiedVecOf { - &mut self.0 - } - fn via(&self) -> &IdentifiedVecOf { - &self.0 - } - fn from_identified_vec_of(identified_vec_of: IdentifiedVecOf) -> Self { - Self(identified_vec_of) - } - } - impl IntoIterator for CollectionOfUsersVia { - type Item = User; - - type IntoIter = IdentifiedVecIntoIterator<::ID, User>; - - fn into_iter(self) -> Self::IntoIter { - todo!() - } - } - - let mut sut = CollectionOfUsersVia::new(); - sut.append(User::blob_jr()); - assert_eq!(sut.items(), [User::blob_jr()]); - sut.remove_at(0); - assert_eq!(sut.len(), 0); - sut.update_or_append(User::blob_sr()); - sut.update_or_append(User::blob_sr()); - assert_eq!(sut.items(), [User::blob_sr()]); - sut.update_or_append(User::blob_jr()); - assert_eq!(sut.items(), [User::blob_sr(), User::blob_jr()]); -} - #[test] fn test_macro() { newtype_identified_vec!(of: User, named: CollectionOfUsers);