artichoke_core/file.rs
1//! File-backed Rust extensions for the Artichoke VM.
2
3/// Rust extension hook that can be required.
4///
5/// `File`s are mounted in the interpreter file system and can modify interpreter
6/// state when they are loaded.
7pub trait File {
8 /// Concrete type for interpreter.
9 type Artichoke;
10
11 /// Concrete error type for eval functions.
12 type Error;
13
14 /// Called when the filename mapped to this type is required by the VM.
15 ///
16 /// This function can mutate interpreter state, such as defining classes and
17 /// modules. This function is equivalent to the "init" methods of
18 /// C-implemented Rubygems.
19 ///
20 /// # Errors
21 ///
22 /// If a fallible API on the interpreter returns an error, implementers
23 /// should return an error. Example fallible APIs that might be called on
24 /// require include [`Eval::eval`](crate::eval::Eval::eval) and
25 /// [`LoadSources::def_rb_source_file`](crate::load::LoadSources::def_rb_source_file).
26 fn require(interp: &mut Self::Artichoke) -> Result<(), Self::Error>;
27}