Skip to content

Commit c1890eb

Browse files
Merge pull request #44 from code0-tech/23-std-runtime-function-text
Runtime Functions for Text
2 parents cd5ffb9 + 48b1b87 commit c1890eb

6 files changed

Lines changed: 1825 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ toml = "0.8.0"
1414
log = "0.4.27"
1515
futures-lite = "2.6.0"
1616
rand = "0.9.1"
17+
base64 = "0.22.1"
1718

1819
[dev-dependencies]
1920
tempfile = "3.19.1"

src/implementation/boolean.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ fn as_number(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError
1717
kind: Some(Kind::BoolValue(value)),
1818
}] = values
1919
else {
20-
return Err(RuntimeError::default());
20+
return Err(RuntimeError::simple(
21+
"InvalidArgumentRuntimeError",
22+
format!("Expected a boolean value but received {:?}", values),
23+
));
2124
};
2225

2326
Ok(Value {
@@ -30,7 +33,10 @@ fn as_text(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
3033
kind: Some(Kind::BoolValue(value)),
3134
}] = values
3235
else {
33-
return Err(RuntimeError::default());
36+
return Err(RuntimeError::simple(
37+
"InvalidArgumentRuntimeError",
38+
format!("Expected a boolean value but received {:?}", values),
39+
));
3440
};
3541

3642
Ok(Value {
@@ -43,7 +49,10 @@ fn from_number(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeErr
4349
kind: Some(Kind::NumberValue(number)),
4450
}] = values
4551
else {
46-
return Err(RuntimeError::default());
52+
return Err(RuntimeError::simple(
53+
"InvalidArgumentRuntimeError",
54+
format!("Expected a number value but received {:?}", values),
55+
));
4756
};
4857

4958
let is_zero = number == &0.0;
@@ -58,12 +67,20 @@ fn from_text(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError
5867
kind: Some(Kind::StringValue(text)),
5968
}] = values
6069
else {
61-
return Err(RuntimeError::default());
70+
return Err(RuntimeError::simple(
71+
"InvalidArgumentRuntimeError",
72+
format!("Expected a string value but received {:?}", values),
73+
));
6274
};
6375

6476
let bool: bool = match text.to_lowercase().parse() {
6577
Ok(value) => value,
66-
Err(_) => return Err(RuntimeError::default()),
78+
Err(_) => {
79+
return Err(RuntimeError::simple(
80+
"InvalidArgumentRuntimeError",
81+
format!("Failed to parse boolean from string: {:?}", text),
82+
))
83+
}
6784
};
6885

6986
Ok(Value {
@@ -78,7 +95,10 @@ fn is_equal(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
7895
kind: Some(Kind::BoolValue(rhs)),
7996
}] = values
8097
else {
81-
return Err(RuntimeError::default());
98+
return Err(RuntimeError::simple(
99+
"InvalidArgumentRuntimeError",
100+
format!("Expected two boolean values but received {:?}", values),
101+
));
82102
};
83103

84104
Ok(Value {
@@ -91,7 +111,10 @@ fn negate(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
91111
kind: Some(Kind::BoolValue(value)),
92112
}] = values
93113
else {
94-
return Err(RuntimeError::default());
114+
return Err(RuntimeError::simple(
115+
"InvalidArgumentRuntimeError",
116+
format!("Expected a boolean value but received {:?}", values),
117+
));
95118
};
96119

97120
Ok(Value {

src/implementation/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
use std::collections::HashMap;
2+
13
use crate::registry::HandlerFn;
24

5+
pub mod boolean;
36
pub mod number;
7+
pub mod text;
48

59
pub fn collect() -> Vec<(&'static str, HandlerFn)> {
610
let mut result = vec![];
711

812
result.extend(number::collect_number_functions());
13+
result.extend(boolean::collect_boolean_functions());
14+
result.extend(text::collect_text_functions());
915

1016
result
1117
}

0 commit comments

Comments
 (0)