Macro to_string

macro_rules! macro to_string

Sometimes I get tired typing in to_string, especially in test cases so I wrote this macro.

examples/macro-to-string/src/main.rs

macro_rules! s(($result:expr) => ($result.to_string()));

fn main() {
    let name = s!("Foo Bar");
    println!("Hello, {}!", name);
}

I am a bit ambivalent as I don't like one-letter variables or functions name, but I want this to be short.

An besides I can search for s! if I am looking for all the uses.

Author

Gabor Szabo (szabgab)

Gabor Szabo, the author of the Rust Maven web site maintains several Open source projects in Rust and while he still feels he has tons of new things to learn about Rust he already offers training courses in Rust and still teaches Python, Perl, git, GitHub, GitLab, CI, and testing.

Gabor Szabo