LINUX.ORG.RU

История изменений

Исправление fsb4000, (текущая версия) :

Разницу между токенами и языком в студию!

fn main() {
    let my_number = 10;
    match my_number {
        10 => println!("You got a ten"),
        _ => 10,
    }
}
It will complain that you want to return () in one case, and i32 in the other.
But a macro doesn't care, because it's just giving an output. It's not a compiler - it's code before code. So you can do this:
macro_rules! six_or_print {
    (6) => {
        6
    };
    () => {
        println!("You didn't give me 6.");
    };
}

fn main() {
    let my_number = six_or_print!(6);
    six_or_print!();
}
So a macro isn't exactly Rust syntax.

// Какая-то книжка по расту, но кто их читает…

Исходная версия fsb4000, :

Разницу между токенами и языком в студию!

fn main() {
    let my_number = 10;
    match my_number {
        10 => println!("You got a ten"),
        _ => 10,
    }
}
It will complain that you want to return () in one case, and i32 in the other.
But a macro doesn't care, because it's just giving an output. It's not a compiler - it's code before code. So you can do this:
macro_rules! six_or_print {
    (6) => {
        6
    };
    () => {
        println!("You didn't give me 6.");
    };
}

fn main() {
    let my_number = six_or_print!(6);
    six_or_print!();
}
So a macro isn't exactly Rust syntax.