Try to work on build some more.

This commit is contained in:
Cutieguwu
2026-02-15 12:25:03 -05:00
parent a9fb52d8d7
commit 0fad1b74bc
5 changed files with 114 additions and 7 deletions

View File

@@ -1,13 +1,14 @@
use std::collections::HashSet;
use std::fs::{File, OpenOptions};
use std::io::Read;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
use crate::class::Class;
use crate::meta::Meta;
use crate::package::Package;
use crate::prelude::Dependency;
pub const F_PREY_TOML: &str = "Prey.toml";
pub const F_PREY_LOCK: &str = "Prey.lock";
@@ -53,11 +54,19 @@ impl TryFrom<File> for Prey {
}
/// Data struct
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)]
pub struct PreyLock {
classes: HashSet<Class>,
pub classes: HashSet<Class>,
}
impl PreyLock {
pub fn with_class(&mut self, class: Class) -> &mut Self {
self.classes.insert(class);
self
}
}
/// Load the PreyLock from Prey.lock file.
impl TryFrom<PathBuf> for PreyLock {
type Error = crate::Error;
@@ -76,3 +85,21 @@ impl TryFrom<File> for PreyLock {
Ok(toml::from_str(buf.as_str())?)
}
}
impl From<Vec<PathBuf>> for PreyLock {
fn from(value: Vec<PathBuf>) -> Self {
let mut lock = Self::default();
lock.classes = value
.iter()
.filter_map(|f| {
let dep = Class::try_from(f.to_owned());
if dep.is_ok() {
Some(dep.unwrap())
} else {
None
}
})
.collect();
lock
}
}