ct_python/
lib.rs

1//! Execute Python code at compile time to generate Rust code.
2//!
3//! # Example
4//!
5//! ```
6//! use ct_python::ct_python;
7//!
8//! static SIN_2: f64 = ct_python! {
9//!     from math import sin
10//!     print(sin(2))
11//! };
12//!
13//! ct_python! {
14//!     print("type num = f64;")
15//! }
16//!
17//! fn main() {
18//!     assert_eq!(num::sin(2.0), SIN_2);
19//! }
20//! ```
21//!
22//! # How to use
23//!
24//! Use the `ct_python!{..}` macro to generate Rust code from an embedded
25//! Python script.
26//! The output of the script (`print()` and anything else through `sys.stdout`)
27//! is captured, and will be parsed as Rust code.
28//!
29//! ## Python Errors
30//!
31//! Any syntax errors or runtime exceptions from the Python code will be
32//! reported by the Rust compiler as compiler errors.
33//!
34//! ## Syntax issues
35//!
36//! Since the Rust tokenizer will tokenize the Python code, some valid Python
37//! code is rejected. See [the `inline-python` documentation][1] for details.
38//!
39//! [1]: https://docs.rs/inline-python/#syntax-issues
40
41/// A block of compile-time executed Rust code generating Python code.
42///
43/// See [the crate's module level documentation](index.html) for examples.
44pub use inline_python_macros::ct_python;