Most of the refactor. Need to switch machines.

This commit is contained in:
Olivia Brooks
2026-02-15 09:36:04 -05:00
parent dda863e512
commit e41d4bcd76
61 changed files with 3390 additions and 618 deletions

78
crates/core/src/prey.rs Normal file
View File

@@ -0,0 +1,78 @@
use std::collections::HashSet;
use std::fs::{File, OpenOptions};
use std::io::Read;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::class::Class;
use crate::meta::Meta;
use crate::package::Package;
pub const F_PREY_TOML: &str = "Prey.toml";
pub const F_PREY_LOCK: &str = "Prey.lock";
/// Data struct
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)]
pub struct Prey {
package: Package,
meta: Meta,
}
impl Prey {
pub fn entry_point(&self) -> PathBuf {
self.package.entry_point.clone()
}
pub fn name(&self) -> String {
self.meta.name.clone()
}
pub fn version(&self) -> semver::Version {
self.meta.version.clone()
}
}
impl TryFrom<PathBuf> for Prey {
type Error = crate::Error;
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
let f = OpenOptions::new().read(true).open(value)?;
Self::try_from(f)
}
}
impl TryFrom<File> for Prey {
type Error = crate::Error;
fn try_from(mut value: File) -> Result<Self, Self::Error> {
let mut buf = String::new();
value.read_to_string(&mut buf)?;
Ok(toml::from_str(buf.as_str())?)
}
}
/// Data struct
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct PreyLock {
classes: HashSet<Class>,
}
impl TryFrom<PathBuf> for PreyLock {
type Error = crate::Error;
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
let f = OpenOptions::new().read(true).open(value)?;
Self::try_from(f)
}
}
impl TryFrom<File> for PreyLock {
type Error = crate::Error;
fn try_from(mut value: File) -> Result<Self, Self::Error> {
let mut buf = String::new();
value.read_to_string(&mut buf)?;
Ok(toml::from_str(buf.as_str())?)
}
}