Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Dec 15, 2023
1 parent 71f1659 commit f9da7dc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
15 changes: 14 additions & 1 deletion identified_vec/src/is_identified_vec_via.rs
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down Expand Up @@ -33,6 +35,17 @@ where
}
}

impl<Element, U> ItemsCloned<Element> for U
where
U: ViaMarker,
Element: Identifiable + Clone,
U: IsIdentifiableVecOfVia<Element>,
{
fn items(&self) -> Vec<Element> {
self.via().items()
}
}

impl<Element, U> IsIdentifiableVec<Element, Element::ID> for U
where
U: ViaMarker,
Expand Down
1 change: 0 additions & 1 deletion identified_vec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
//! let numbers = IdentifiedVec::<u32, u32>::new_identifying_element(|e| *e);
//! ```
mod Is_identifiable_vec;
mod conflict_resolution_choice;
mod errors;
mod identifiable_trait;
Expand Down
11 changes: 9 additions & 2 deletions identified_vec/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,14 @@ where
}
}

impl<I, E> IdentifiedVec<I, E>
pub trait ItemsCloned<Element>
where
Element: Clone,
{
fn items(&self) -> Vec<Element>;
}

impl<I, E> ItemsCloned<E> for IdentifiedVec<I, E>
where
E: Clone,
I: Eq + Hash + Clone + Debug,
Expand All @@ -659,7 +666,7 @@ where
///
/// - Complexity: O(n)
#[inline]
pub fn items(&self) -> Vec<E> {
fn items(&self) -> Vec<E> {
self.iter().map(|e| e.clone()).collect()
}
}
Expand Down
7 changes: 0 additions & 7 deletions identified_vec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
};
}
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f9da7dc

Please sign in to comment.