forked from Cutieguwu/raven
Try to work on build some more.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user