Skip to main content

rl_lang/interpreter/stdlib/types/
string.rs

1use crate::interpreter::{
2    evaluator::Evaluator,
3    stdlib::common::{verr, vok, vs},
4    values::Value,
5};
6
7pub fn std_is_string(_: &mut Evaluator, value: Value) -> bool {
8    matches!(value, Value::String(_))
9}
10
11pub fn std_to_string(_: &mut Evaluator, value: Value) -> Value {
12    let result = match value {
13        Value::Integer(v) => format!("{}", v),
14        Value::Byte(v) => format!("{}", v),
15        Value::Float(v) => format!("{}", v),
16        Value::Bool(v) => format!("{}", v),
17        Value::Char(v) => v.to_string(),
18        Value::String(s) => s,
19
20        other => {
21            return verr!(vs!(format!(
22                "cannot parse \"{}\" as string",
23                other.type_name()
24            )));
25        }
26    };
27    vok!(vs!(result))
28}