Skip to content

Commit 91b3bbc

Browse files
committed
Add doc comments
1 parent 95c1392 commit 91b3bbc

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
//! This is the `rustpython` binary. If you're looking to embed RustPython into your application,
2+
//! you're likely looking for the [`rustpython-vm`](https://docs.rs/rustpython-vm) crate.
3+
//!
4+
//! You can install `rustpython` with `cargo install rustpython`, or if you'd like to inject your
5+
//! own native modules you can make a binary crate that depends on the `rustpython` crate (and
6+
//! probably `rustpython-vm`, too), and make a `main.rs` that looks like:
7+
//!
8+
//! ```no_run
9+
//! use rustpython_vm::{pymodule, py_freeze};
10+
//! fn main() {
11+
//! rustpython::run(|vm| {
12+
//! vm.add_native_module("mymod".to_owned(), Box::new(mymod::make_module));
13+
//! vm.add_frozen(py_freeze!(source = "def foo(): pass", module_name = "otherthing"));
14+
//! });
15+
//! }
16+
//!
17+
//! #[pymodule]
18+
//! mod mymod {
19+
//! use rustpython_vm::builtins::PyStrRef;
20+
//TODO: use rustpython_vm::prelude::*;
21+
//! use rustpython_vm::common::borrow::BorrowValue;
22+
//!
23+
//! #[pyfunction]
24+
//! fn do_thing(x: i32) -> i32 {
25+
//! x + 1
26+
//! }
27+
//!
28+
//! #[pyfunction]
29+
//! fn other_thing(s: PyStrRef) -> (String, usize) {
30+
//! let new_string = format!("hello from rust, {}!", s);
31+
//! let prev_len = s.borrow_value().len();
32+
//! (new_string, prev_len)
33+
//! }
34+
//! }
35+
//! ```
36+
//!
37+
//! The binary will have all the standard arguments of a python interpreter (including a REPL!) but
38+
//! it will have your modules loaded into the vm.
39+
140
#[macro_use]
241
extern crate clap;
342
extern crate env_logger;
@@ -25,6 +64,8 @@ mod shell;
2564

2665
pub use rustpython_vm;
2766

67+
/// The main cli of the `rustpython` interpreter. This function will exit with `process::exit()`
68+
/// based on the return code of the python code ran through the cli.
2869
pub fn run<F>(init: F) -> !
2970
where
3071
F: FnOnce(&mut VirtualMachine),

0 commit comments

Comments
 (0)