diff --git a/src/app/collection/index.rs b/src/app/collection/index.rs index b9c3616..d9f8416 100644 --- a/src/app/collection/index.rs +++ b/src/app/collection/index.rs @@ -164,9 +164,7 @@ impl From<&collection::Song> for SongKey { impl From<&SongKey> for SongID { fn from(key: &SongKey) -> Self { - let mut hasher = DefaultHasher::default(); - key.hash(&mut hasher); - SongID(hasher.finish()) + SongID(key.id()) } } @@ -212,9 +210,7 @@ impl From<&collection::Song> for AlbumKey { impl From<&AlbumKey> for AlbumID { fn from(key: &AlbumKey) -> Self { - let mut hasher = DefaultHasher::default(); - key.hash(&mut hasher); - AlbumID(hasher.finish()) + AlbumID(key.id()) } } @@ -225,6 +221,18 @@ impl From<&collection::Song> for AlbumID { } } +trait ID { + fn id(&self) -> u64; +} + +impl ID for T { + fn id(&self) -> u64 { + let mut hasher = DefaultHasher::default(); + self.hash(&mut hasher); + hasher.finish() + } +} + #[cfg(test)] mod test {