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 {
|
impl From<&SongKey> for SongID {
|
||||||
fn from(key: &SongKey) -> Self {
|
fn from(key: &SongKey) -> Self {
|
||||||
let mut hasher = DefaultHasher::default();
|
SongID(key.id())
|
||||||
key.hash(&mut hasher);
|
|
||||||
SongID(hasher.finish())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,9 +210,7 @@ impl From<&collection::Song> for AlbumKey {
|
||||||
|
|
||||||
impl From<&AlbumKey> for AlbumID {
|
impl From<&AlbumKey> for AlbumID {
|
||||||
fn from(key: &AlbumKey) -> Self {
|
fn from(key: &AlbumKey) -> Self {
|
||||||
let mut hasher = DefaultHasher::default();
|
AlbumID(key.id())
|
||||||
key.hash(&mut hasher);
|
|
||||||
AlbumID(hasher.finish())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue