artichoke_core/eval.rs
1//! Run code on an Artichoke interpreter.
2
3#[cfg(feature = "std")]
4use std::ffi::OsStr;
5#[cfg(feature = "std")]
6use std::path::Path;
7
8use crate::value::Value;
9
10/// Execute code and retrieve its result.
11pub trait Eval {
12 /// Concrete type for return values from eval.
13 type Value: Value;
14
15 /// Concrete error type for eval functions.
16 type Error;
17
18 /// Eval code on the Artichoke interpreter using the current parser context.
19 ///
20 /// # Errors
21 ///
22 /// If an exception is raised on the interpreter, then an error is returned.
23 fn eval(&mut self, code: &[u8]) -> Result<Self::Value, Self::Error>;
24
25 /// Eval code on the Artichoke interpreter using the current parser context
26 /// when given code as an [`OsStr`].
27 ///
28 /// # Errors
29 ///
30 /// If an exception is raised on the interpreter, then an error is returned.
31 ///
32 /// If `code` cannot be converted to a `&[u8]` on the current platform, then
33 /// an error is returned.
34 #[cfg(feature = "std")]
35 #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
36 fn eval_os_str(&mut self, code: &OsStr) -> Result<Self::Value, Self::Error>;
37
38 /// Eval code on the Artichoke interpreter using a new file `Context` given
39 /// a file path.
40 ///
41 /// # Errors
42 ///
43 /// If an exception is raised on the interpreter, then an error is returned.
44 ///
45 /// If `path` does not exist or code cannot be read, an error is returned.
46 #[cfg(feature = "std")]
47 #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
48 fn eval_file(&mut self, file: &Path) -> Result<Self::Value, Self::Error>;
49}