Docs.rs
  • ct-python-0.5.12
    • ct-python 0.5.12
    • Permalink
    • Docs.rs crate page
    • BSD-2-Clause
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • m-ou-se
    • de-vri-es
    • Dependencies
      • pyo3 ^0.25 normal
      • libc ^0.2.71 normal
    • Versions
    • 100% of the crate is documented
  • Platform
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate ct_python

ct_python0.5.12

  • All Items

Sections

  • Example
  • How to use
    • Python Errors
    • Syntax issues

Crate Items

  • Macros

Crates

  • ct_python

Crate ct_python

Source
Expand description

Execute Python code at compile time to generate Rust code.

§Example

use ct_python::ct_python;

static SIN_2: f64 = ct_python! {
    from math import sin
    print(sin(2))
};

ct_python! {
    print("type num = f64;")
}

fn main() {
    assert_eq!(num::sin(2.0), SIN_2);
}

§How to use

Use the ct_python!{..} macro to generate Rust code from an embedded Python script. The output of the script (print() and anything else through sys.stdout) is captured, and will be parsed and injected as Rust code.

§Python Errors

Any syntax errors and runtime exceptions from the Python code will be reported by the Rust compiler as compiler errors.

§Syntax issues

Since the Rust tokenizer will tokenize the Python code, some valid Python code is rejected. See the inline-python documentation for details.

Macros§

ct_python
A block of compile-time executed Rust code generating Python code.

Results

Settings
Help
    extern crate
    ct_python
    Execute Python code at compile time to generate Rust code.
    macro
    ct_python::ct_python
    A block of compile-time executed Rust code generating …
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.