feat: use sets etc.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use anyhow::{Result, anyhow, bail};
|
||||
use derive_more::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{collections::BTreeSet, path::{Path, PathBuf}};
|
||||
use tokio::fs;
|
||||
use crate::{model::{local, rainy}, util};
|
||||
|
||||
@ -10,7 +10,7 @@ use crate::{model::{local, rainy}, util};
|
||||
pub struct PkgKey(pub String);
|
||||
|
||||
// {namespace}-{name}-{version}
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Eq, Hash, PartialEq, PartialOrd, Ord, Clone, Serialize, Deserialize, Display)]
|
||||
pub struct PkgKeyVersion(String);
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize)]
|
||||
@ -36,7 +36,7 @@ pub enum Kind {
|
||||
pub struct Local {
|
||||
pub version: String,
|
||||
pub path: PathBuf,
|
||||
pub dependencies: Vec<PkgKey>,
|
||||
pub dependencies: BTreeSet<PkgKey>,
|
||||
pub kind: Kind
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ pub struct Remote {
|
||||
pub package_url: String,
|
||||
pub download_url: String,
|
||||
pub deprecated: bool,
|
||||
pub dependencies: Vec<PkgKey>
|
||||
pub dependencies: BTreeSet<PkgKey>
|
||||
}
|
||||
|
||||
impl Package {
|
||||
@ -154,16 +154,16 @@ impl Package {
|
||||
}
|
||||
}
|
||||
|
||||
fn sanitize_deps(mut deps: Vec<PkgKeyVersion>) -> Vec<PkgKey> {
|
||||
fn sanitize_deps(src: BTreeSet<PkgKeyVersion>) -> BTreeSet<PkgKey> {
|
||||
let regex = regex::Regex::new(r"([A-Za-z0-9_]+)-([A-Za-z0-9_]+)-[0-9\.]+$")
|
||||
.expect("Invalid regex");
|
||||
let mut res = BTreeSet::<PkgKey>::new();
|
||||
|
||||
for i in 0..deps.len() {
|
||||
let caps = regex.captures(&deps[i].0)
|
||||
for dep in src {
|
||||
let caps = regex.captures(&dep.0)
|
||||
.expect("Invalid dependency");
|
||||
deps[i] = PkgKeyVersion(format!("{}-{}", caps.get(1).unwrap().as_str(), caps.get(2).unwrap().as_str()));
|
||||
res.insert(PkgKey(format!("{}-{}", caps.get(1).unwrap().as_str(), caps.get(2).unwrap().as_str())));
|
||||
}
|
||||
let rv: Vec<PkgKey> = unsafe { std::mem::transmute(deps) };
|
||||
rv
|
||||
res
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user