forked from Cutieguwu/raven
Most of the refactor. Need to switch machines.
This commit is contained in:
56
crates/core/src/package.rs
Normal file
56
crates/core/src/package.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use std::hash::Hash;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::prey::{F_PREY_LOCK, F_PREY_TOML, Prey, PreyLock};
|
||||
|
||||
/// Hashing is only based off the Prey.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PackageHandler {
|
||||
prey: Prey,
|
||||
prey_lock: Option<PreyLock>,
|
||||
package_root: PathBuf,
|
||||
target_dir: PathBuf,
|
||||
}
|
||||
|
||||
impl PackageHandler {
|
||||
pub fn new<P: AsRef<Path>>(package_root: P, target_dir: P) -> crate::Result<Self> {
|
||||
let package_root = package_root.as_ref().to_path_buf();
|
||||
|
||||
Ok(Self {
|
||||
prey: Prey::try_from(package_root.join(F_PREY_TOML))?,
|
||||
prey_lock: PreyLock::try_from(package_root.join(F_PREY_LOCK)).ok(),
|
||||
package_root,
|
||||
target_dir: target_dir.as_ref().to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update_class_cache(&self) {}
|
||||
|
||||
pub fn entry_point(&self) -> PathBuf {
|
||||
self.prey.entry_point()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
self.prey.name()
|
||||
}
|
||||
|
||||
pub fn version(&self) -> semver::Version {
|
||||
self.prey.version()
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for PackageHandler {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.prey.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
/// Data struct
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Package {
|
||||
pub entry_point: PathBuf,
|
||||
}
|
||||
|
||||
//impl Into<Dependency> for Package {}
|
||||
Reference in New Issue
Block a user