Working example

This commit is contained in:
2023-03-10 13:58:16 +00:00
parent 35a081162f
commit 180ebb56fa
62 changed files with 1487 additions and 372 deletions

27
src/external/runtime_error.rs vendored Normal file
View File

@@ -0,0 +1,27 @@
use std::{rc::Rc, fmt::Display};
use crate::foreign::ExternError;
#[derive(Clone)]
pub struct RuntimeError {
message: String,
operation: &'static str,
}
impl RuntimeError {
pub fn fail(message: String, operation: &'static str) -> Result<!, Rc<dyn ExternError>> {
return Err(Self { message, operation }.into_extern())
}
pub fn ext(message: String, operation: &'static str) -> Rc<dyn ExternError> {
return Self { message, operation }.into_extern()
}
}
impl Display for RuntimeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Error while {}: {}", self.operation, self.message)
}
}
impl ExternError for RuntimeError{}