fn deduplicate<K>(files: Vec<FileInfoNoLen>, key: impl Fn(&Path) -> K) -> Vec<FileInfoNoLen>
where
    K: Eq + std::hash::Hash,
{
    files
        .into_iter()
        // need to unpack the struct before accessing path reference
        // referencing fields of a packed struct directly is UB, because they may be unaligned
        .map(|i| (i.path, i.id_hash))
        .unique_by(|(path, _)| (key)(path))
        .map(|(path, id_hash)| FileInfoNoLen { path, id_hash })
        .collect()
}
/// Deduplicates a vector of file information objects by given key.
Deduplicates a vector of file information objects by given key.
Deduplicates a vector of file information objects by given key .
fn deduplicate<K>(files: Vec<FileInfoNoLen>, key: impl Fn(&Path) -> K) -> Vec<FileInfoNoLen>
where
    K: Eq + std::hash::Hash,
{
    files
        .into_iter()
        // need to unpack the struct before accessing path reference
        // referencing fields of a packed struct directly is UB, because they may be unaligned
        .map(|i| (i.path, i.id_hash))
        .unique_by(|(path, _)| (key)(path))
        .map(|(path, id_hash)| FileInfoNoLen { path, id_hash })
        .collect()
}
fn deduplicate < K > ( files : Vec < FileInfoNoLen > , key : impl Fn ( & Path ) -> K ) -> Vec < FileInfoNoLen > where K : Eq + std :: hash :: Hash , { files . into_iter ( ) // need to unpack the struct before accessing path reference // referencing fields of a packed struct directly is UB, because they may be unaligned . map ( | i | ( i . path , i . id_hash ) ) . unique_by ( | ( path , _ ) | ( key ) ( path ) ) . map ( | ( path , id_hash ) | FileInfoNoLen { path , id_hash } ) . collect ( ) }
Deduplicates a vector of file information objects by given key.
Deduplicates a vector of file information objects by given key .
files
Vec<FileInfoNoLen>
key
impl Fn(&Path) -> K
files
Vec<FileInfoNoLen>
key
impl Fn(&Path) -> K