Skip to content

Commit dc122b0

Browse files
committed
feat: added signal to replace primitive result
1 parent 0c9767d commit dc122b0

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/context/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub struct Context {
2+
3+
}

src/context/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
pub mod signal;
2+
pub mod context;
3+
14
use crate::error::RuntimeError;
25
use std::{
36
collections::{HashMap, VecDeque},

src/context/signal.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use tucana::shared::Value;
2+
use crate::error::RuntimeError;
3+
4+
#[derive(Debug)]
5+
pub enum Signal {
6+
Success(Value),
7+
Failure(RuntimeError),
8+
Return(Value),
9+
Stop
10+
}
11+
12+
impl PartialEq for Signal {
13+
fn eq(&self, other: &Self) -> bool {
14+
matches!(
15+
(self, other),
16+
(Signal::Success(_), Signal::Success(_))
17+
| (Signal::Failure(_), Signal::Failure(_))
18+
| (Signal::Return(_), Signal::Return(_))
19+
| (Signal::Stop, Signal::Stop)
20+
)
21+
}
22+
}

src/registry/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::{context::Context, error::RuntimeError};
1+
use crate::{context::Context};
22
use std::collections::HashMap;
33
use tucana::shared::Value;
4+
use crate::context::signal::Signal;
45

5-
pub type HandlerFn = fn(&[Value], &mut Context) -> Result<Value, RuntimeError>;
6+
pub type HandlerFn = fn(&[Value], &mut Context) -> Signal;
67

78
/// Holds all registered handlers.
89
pub struct FunctionStore {

0 commit comments

Comments
 (0)