Most of the refactor. Need to switch machines.
This commit is contained in:
43
crates/core/src/dependency.rs
Normal file
43
crates/core/src/dependency.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::package::PackageHandler;
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Dependency {
|
||||
name: String,
|
||||
version: Version,
|
||||
pub checksum: String,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
source: Option<String>, // Path / URL
|
||||
}
|
||||
|
||||
impl Dependency {
|
||||
/// Returns a path to the dependency in local storage
|
||||
/// if there is one.
|
||||
pub fn local_path(&self) -> String {
|
||||
if self.source.as_ref().is_some_and(|path| !is_url(path)) {
|
||||
return self.source.clone().unwrap();
|
||||
}
|
||||
|
||||
// TODO: Convert from reverse domain name to path.
|
||||
return self.name.clone();
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PackageHandler> for Dependency {
|
||||
fn from(value: PackageHandler) -> Self {
|
||||
Dependency {
|
||||
name: value.name(),
|
||||
version: value.version(),
|
||||
checksum: String::new(),
|
||||
source: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: This is just a placeholder at present.
|
||||
fn is_url<S: ToString>(path: S) -> bool {
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user