crev_data/
url.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use derive_builder::Builder;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Builder, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Url {
    pub url: String,
    #[serde(
        rename = "url-type",
        skip_serializing_if = "equals_default_url_type",
        default = "default_url_type"
    )]
    pub url_type: String,
}

impl Url {
    pub fn new_git<Stringy: Into<String>>(url: Stringy) -> Self {
        Self {
            url: url.into(),
            url_type: default_url_type(),
        }
    }

    #[must_use]
    pub fn digest(&self) -> crate::Digest {
        let digest = crev_common::blake2b256sum(self.url.to_ascii_lowercase().as_bytes());
        digest.into()
    }
}

pub(crate) fn equals_default_url_type(s: &str) -> bool {
    s == default_url_type()
}

pub(crate) fn default_url_type() -> String {
    "git".into()
}