easy_install/
artifact.rs

1use compact_str::CompactString;
2use serde::Deserialize;
3use std::hash::Hash;
4use std::{borrow::Borrow, collections::HashSet, hash::Hasher};
5use url::Url;
6
7#[derive(Eq, Deserialize, Debug)]
8pub struct Artifact {
9    pub name: CompactString,
10    pub url: Url,
11    pub browser_download_url: String,
12}
13
14// Manually implement PartialEq and Hash to ensure it will always produce the
15// same hash as a str with the same content, and that the comparison will be
16// the same to coparing a string.
17
18impl PartialEq for Artifact {
19    fn eq(&self, other: &Self) -> bool {
20        self.name.eq(&other.name)
21    }
22}
23
24impl Hash for Artifact {
25    fn hash<H>(&self, state: &mut H)
26    where
27        H: Hasher,
28    {
29        let s: &str = self.name.as_str();
30        s.hash(state)
31    }
32}
33
34// Implement Borrow so that we can use call
35// `HashSet::contains::<str>`
36
37impl Borrow<str> for Artifact {
38    fn borrow(&self) -> &str {
39        &self.name
40    }
41}
42
43#[derive(Debug, Default, Deserialize)]
44pub struct Artifacts {
45    pub assets: HashSet<Artifact>,
46}