Skip to main content

rl_lang/interpreter/stdlib/path/
path_parent.rs

1use crate::{
2    interpreter::{evaluator::Evaluator, values::Value},
3    utils::{errors::Error, span::Span},
4};
5
6pub fn std_path_parent(eval: &mut Evaluator, path: Value, span: Span) -> Result<Value, Error> {
7    match path {
8        Value::String(s) => Ok(Value::String(
9            std::path::Path::new(&s)
10                .parent()
11                .ok_or_else(|| eval.err("path was not found".to_string(), span))?
12                .to_string_lossy()
13                .to_string(),
14        )),
15        other => Err(eval.err(
16            format!("path_parent() expects a string, got {}", other.type_name()),
17            span,
18        )),
19    }
20}