Adds ID trait
This commit is contained in:
parent
93e8d7d94b
commit
8db6a2352b
1 changed files with 14 additions and 6 deletions
|
@ -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<T: Hash> ID for T {
|
||||
fn id(&self) -> u64 {
|
||||
let mut hasher = DefaultHasher::default();
|
||||
self.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue