MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

examples/call_between_rust_and_python.rs:6–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4};
5
6pub fn main() {
7 let builder = rustpython::Interpreter::builder(Default::default());
8 let def = rust_py_module::module_def(&builder.ctx);
9 let interp = builder.init_stdlib().add_native_module(def).build();
10
11 interp.enter(|vm| {
12 vm.insert_sys_path(vm.new_pyobj("examples"))
13 .expect("add path");
14
15 let module = vm.import("call_between_rust_and_python", 0).unwrap();
16 let init_fn = module.get_attr("python_callback", vm).unwrap();
17 init_fn.call((), vm).unwrap();
18
19 let take_string_fn = module.get_attr("take_string", vm).unwrap();
20 take_string_fn
21 .call((String::from("Rust string sent to python"),), vm)
22 .unwrap();
23 })
24}
25
26#[pymodule]
27mod rust_py_module {

Callers

nothing calls this directly

Calls 10

add_native_moduleMethod · 0.80
init_stdlibMethod · 0.80
insert_sys_pathMethod · 0.80
new_pyobjMethod · 0.80
buildMethod · 0.45
enterMethod · 0.45
unwrapMethod · 0.45
importMethod · 0.45
get_attrMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected