Expand description
Expression-to-Rust translation helpers.
Converts Python AST expression nodes into Rust source strings. All functions are pure (no I/O, no state).
Functions§
- constant_
to_ rust - Convert a Python constant value to its Rust literal equivalent.
- expr_
to_ rust - Translate a Python expression to a Rust expression string.
- translate_
for_ iter - Translate a Python for-loop iterator expression to a Rust range string.
Handles:
range(n)→0..n,range(a, b)→a..b, fallback to expr_to_rust. - translate_
len_ guard - Translate a Python if-test that guards a length check into a Rust guard string.
Returns
Noneif the test is not a simple equality/inequality comparison. - translate_
while_ test - Translate a Python while-loop test expression to Rust.