Crate rustpython

Source
Expand description

This is the rustpython binary. If you’re looking to embed RustPython into your application, you’re likely looking for the rustpython-vm crate.

You can install rustpython with cargo install rustpython, or if you’d like to inject your own native modules you can make a binary crate that depends on the rustpython crate (and probably rustpython-vm, too), and make a main.rs that looks like:

use rustpython_vm::{pymodule, py_freeze};
fn main() {
    rustpython::run(|vm| {
        vm.add_native_module("mymod".to_owned(), Box::new(mymod::make_module));
        vm.add_frozen(py_freeze!(source = "def foo(): pass", module_name = "otherthing"));
    });
}

#[pymodule]
mod mymod {
    use rustpython_vm::builtins::PyStrRef;

    #[pyfunction]
    fn do_thing(x: i32) -> i32 {
        x + 1
    }

    #[pyfunction]
    fn other_thing(s: PyStrRef) -> (String, usize) {
        let new_string = format!("hello from rust, {}!", s);
        let prev_len = s.as_str().len();
        (new_string, prev_len)
    }
}

The binary will have all the standard arguments of a python interpreter (including a REPL!) but it will have your modules loaded into the vm.

Re-exports§

pub use rustpython_vm as vm;

Structs§

InterpreterConfig
The convenient way to create rustpython_vm::Interpreter with stdlib and other stuffs.

Enums§

RunMode

Functions§

opts_with_clap
run
The main cli of the rustpython interpreter. This function will return std::process::ExitCode based on the return code of the python code ran through the cli.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy