-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::{ | ||
identified_vec_into_iterator::IdentifiedVecIntoIterator, Identifiable, IdentifiedVecOf, | ||
IsIdentifiableVecOfVia, ViaMarker, | ||
}; | ||
|
||
pub struct IdentifiedVecVia<Element: Identifiable>(IdentifiedVecOf<Element>); | ||
|
||
impl<Element: Identifiable> ViaMarker for IdentifiedVecVia<Element> {} | ||
impl<Element: Identifiable> IsIdentifiableVecOfVia<Element> for IdentifiedVecVia<Element> { | ||
fn via_mut(&mut self) -> &mut IdentifiedVecOf<Element> { | ||
&mut self.0 | ||
} | ||
|
||
fn via(&self) -> &IdentifiedVecOf<Element> { | ||
&self.0 | ||
} | ||
|
||
fn from_identified_vec_of(identified_vec_of: IdentifiedVecOf<Element>) -> Self { | ||
Self(identified_vec_of) | ||
} | ||
} | ||
|
||
impl<Element: Identifiable + std::fmt::Display + std::fmt::Debug> std::fmt::Display | ||
for IdentifiedVecVia<Element> | ||
{ | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
std::fmt::Display::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl<Element: Identifiable> IntoIterator for IdentifiedVecVia<Element> { | ||
type Item = Element; | ||
type IntoIter = IdentifiedVecIntoIterator<<Element as Identifiable>::ID, Element>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
Self::IntoIter::new(self.0) | ||
} | ||
} | ||
|
||
#[cfg(any(test, feature = "serde"))] | ||
impl<Element: Identifiable> serde::Serialize for IdentifiedVecVia<Element> | ||
where | ||
Element: serde::Serialize + Identifiable + std::fmt::Debug + Clone, | ||
{ | ||
fn serialize<S>( | ||
&self, | ||
serializer: S, | ||
) -> Result<<S as serde::Serializer>::Ok, <S as serde::Serializer>::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
IdentifiedVecOf::serialize(&self.0, serializer) | ||
} | ||
} | ||
|
||
#[cfg(any(test, feature = "serde"))] | ||
impl<'de, Element> serde::Deserialize<'de> for IdentifiedVecVia<Element> | ||
where | ||
Element: serde::Deserialize<'de> + Identifiable + std::fmt::Debug + Clone, | ||
{ | ||
#[cfg(not(tarpaulin_include))] // false negative | ||
fn deserialize<D: serde::Deserializer<'de>>( | ||
deserializer: D, | ||
) -> Result<IdentifiedVecVia<Element>, D::Error> { | ||
let id_vec_of = IdentifiedVecOf::<Element>::deserialize(deserializer)?; | ||
return Ok(Self::from_identified_vec_of(id_vec_of)); | ||
} | ||
} |
6 changes: 2 additions & 4 deletions
6
src/vec_of/is_identified_vec_of_via.rs → src/via/is_identified_vec_of_via.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod identified_vec_via; | ||
mod is_identified_vec_of_via; | ||
mod newtype_identified_vec_of; | ||
|
||
pub use identified_vec_via::*; | ||
pub use is_identified_vec_of_via::*; | ||
pub use newtype_identified_vec_of::*; |
File renamed without changes.