1use std::convert::Infallible;
2use std::path::Path;
3use std::str::FromStr;
4
5#[derive(Debug, Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
11pub struct ArchiveId(String);
12
13impl Default for ArchiveId {
14 fn default() -> Self {
15 Self::new()
16 }
17}
18
19impl ArchiveId {
20 pub(crate) fn new() -> Self {
22 Self(uv_fastid::Id::secure().to_string())
23 }
24
25 pub fn from_digest(digest: String) -> Self {
30 Self(digest)
31 }
32}
33
34impl AsRef<Path> for ArchiveId {
35 fn as_ref(&self) -> &Path {
36 self.0.as_ref()
37 }
38}
39
40impl std::fmt::Display for ArchiveId {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 self.0.fmt(f)
43 }
44}
45
46impl FromStr for ArchiveId {
47 type Err = Infallible;
48
49 fn from_str(s: &str) -> Result<Self, Self::Err> {
50 Ok(Self(s.to_string()))
51 }
52}