From 6dc93c5e5a4f6e664401b182dd9d5489ea8e953f Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Tue, 1 Dec 2020 15:20:02 -0600 Subject: [PATCH] Add doc comments --- src/lib.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 56ab26413..2ef1def6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,43 @@ +//! This is the `rustpython` binary. If you're looking to embed RustPython into your application, +//! you're likely looking for the [`rustpython-vm`](https://docs.rs/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: +//! +//! ```no_run +//! 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; +//TODO: use rustpython_vm::prelude::*; +//! use rustpython_vm::common::borrow::BorrowValue; +//! +//! #[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.borrow_value().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. +#![allow(clippy::needless_doctest_main)] + #[macro_use] extern crate clap; extern crate env_logger; @@ -25,6 +65,8 @@ mod shell; pub use rustpython_vm; +/// The main cli of the `rustpython` interpreter. This function will exit with `process::exit()` +/// based on the return code of the python code ran through the cli. pub fn run(init: F) -> ! where F: FnOnce(&mut VirtualMachine),