diff --git a/identified_vec/src/is_identified_vec_via.rs b/identified_vec/src/is_identified_vec_via.rs index 7383c83..fea11b6 100644 --- a/identified_vec/src/is_identified_vec_via.rs +++ b/identified_vec/src/is_identified_vec_via.rs @@ -1,5 +1,7 @@ use crate::conflict_resolution_choice::ConflictResolutionChoice; -use crate::{Error, Identifiable, IdentifiedVecOf, IsIdentifiableVec, IsIdentifiableVecOf}; +use crate::{ + Error, Identifiable, IdentifiedVecOf, IsIdentifiableVec, IsIdentifiableVecOf, ItemsCloned, +}; /// https://stackoverflow.com/a/66537661/1311272 pub trait ViaMarker {} @@ -33,6 +35,17 @@ where } } +impl ItemsCloned for U +where + U: ViaMarker, + Element: Identifiable + Clone, + U: IsIdentifiableVecOfVia, +{ + fn items(&self) -> Vec { + self.via().items() + } +} + impl IsIdentifiableVec for U where U: ViaMarker, diff --git a/identified_vec/src/lib.rs b/identified_vec/src/lib.rs index 91ba1ad..aa673c4 100644 --- a/identified_vec/src/lib.rs +++ b/identified_vec/src/lib.rs @@ -116,7 +116,6 @@ //! let numbers = IdentifiedVec::::new_identifying_element(|e| *e); //! ``` -mod Is_identifiable_vec; mod conflict_resolution_choice; mod errors; mod identifiable_trait; diff --git a/identified_vec/src/vec.rs b/identified_vec/src/vec.rs index b49566e..5af645e 100644 --- a/identified_vec/src/vec.rs +++ b/identified_vec/src/vec.rs @@ -646,7 +646,14 @@ where } } -impl IdentifiedVec +pub trait ItemsCloned +where + Element: Clone, +{ + fn items(&self) -> Vec; +} + +impl ItemsCloned for IdentifiedVec where E: Clone, I: Eq + Hash + Clone + Debug, @@ -659,7 +666,7 @@ where /// /// - Complexity: O(n) #[inline] - pub fn items(&self) -> Vec { + fn items(&self) -> Vec { self.iter().map(|e| e.clone()).collect() } } diff --git a/identified_vec_macros/src/lib.rs b/identified_vec_macros/src/lib.rs index 56a6915..350e8e6 100644 --- a/identified_vec_macros/src/lib.rs +++ b/identified_vec_macros/src/lib.rs @@ -17,12 +17,5 @@ macro_rules! newtype_identified_vec { Self(identified_vec_of) } } - - impl $struct_name { - #[inline] - pub fn items(&self) -> Vec<$item_ty> { - self.0.items() - } - } }; } diff --git a/tests/tests.rs b/tests/tests.rs index e7ba4c9..defbc62 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -3,7 +3,7 @@ use std::{cell::RefCell, collections::HashSet, fmt::Debug, ops::Deref}; use identified_vec::{ ConflictResolutionChoice, Error, Identifiable, IdentifiedVec, IdentifiedVecOf, IdentifiedVecOfSerdeFailure, IsIdentifiableVec, IsIdentifiableVecOf, IsIdentifiableVecOfVia, - ViaMarker, + ItemsCloned, ViaMarker, }; use identified_vec_macros::newtype_identified_vec;