py_fstr

Crates.iopy_fstr
lib.rspy_fstr
version0.1.0
sourcesrc
created_at2023-04-10 19:45:09.636647
updated_at2023-04-10 19:45:09.636647
descriptionA macro for making Python like fstrings
homepagehttps://github.com/AharonSambol/rust_macros/tree/main/py_fstr
repositoryhttps://github.com/AharonSambol/rust_macros/tree/main/py_fstr
max_upload_size
id835388
size5,565
(AharonSambol)

documentation

https://github.com/AharonSambol/rust_macros/tree/main/py_fstr

README

Python fString Macro

Macro for Python-like f-strings in Rust.

Basically just the format! macro but lets you put any expression in the braces

Python:

def add_one(i: int) -> int:
    return i + 1

def main():
    b = 3
    a = f"awow look { add_one(b * 2) }!"
    print(a)

Rust equivalent:

use py_fstr::f;

fn add_one(i: i32) -> i32 {
    i + 1
}

fn main() {
    let b = 3;
    let a = f!("awow look { add_one(b * 2) }!");
    println!("{a}");
}

Install

Add the following line to your Cargo.toml file:

py_fstr = "0.1.0"
Commit count: 0

cargo fmt