- updated common with new compiler/builder trait to provide a common

interface for build tools
- updated editor and build tooling to use new system
This commit is contained in:
2026-02-22 21:43:22 +00:00
parent 4ed5da259e
commit 7117b927f3
9 changed files with 203 additions and 129 deletions
+52
View File
@@ -0,0 +1,52 @@
use std::{
fmt,
path::{Path, PathBuf},
};
#[derive(Debug, Clone)]
pub enum BuildError {
IoError(String),
Generic(String),
}
impl From<std::io::Error> for BuildError {
fn from(err: std::io::Error) -> Self {
Self::IoError(err.to_string())
}
}
impl From<Box<dyn std::error::Error>> for BuildError {
fn from(err: Box<dyn std::error::Error>) -> Self {
Self::Generic(err.to_string())
}
}
impl fmt::Display for BuildError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::IoError(err) => write!(f, "IO Error: {err}"),
Self::Generic(err) => write!(f, "Generic Error: {err}"),
}
}
}
pub trait Builder {
type Output: Clone + std::convert::AsRef<[u8]>;
fn new(src_path: impl Into<PathBuf>) -> Self;
// starts compilation
fn start(&mut self);
// non-blocking function, returns output if completed
fn poll(&mut self) -> Option<Result<Self::Output, BuildError>>;
// blocking function, returns output when completed.
fn output(&mut self) -> Result<Self::Output, BuildError>;
fn write_result(&mut self, path: impl AsRef<Path>) -> Result<(), BuildError> {
let output = self.output()?;
std::fs::write(path.as_ref(), output)
.map_err(|e| BuildError::IoError(e.to_string()))
}
}
+1
View File
@@ -12,6 +12,7 @@
clippy::match_wildcard_for_single_variants
)]
pub mod build;
pub mod instructions;
pub mod logging;