L-value matcher for macros


#1

How can I write a l-value matcher in a macro?

my_request!(array[index], value); // should be transpiled to array[index] = value;

#2

Same way as any other expression:

macro_rules! my_request {
    ($lhs:expr, $rhs:expr) => { $lhs = $rhs };
}

fn main() {
    let mut array = [0; 10];
    let index = 4;
    let value = 7;
    my_request!(array[index], value);
    println!("{:?}", &array[..]);
}

#3

Oh!
I might mistook to extract my problem.
My original code is a little complicated and I tried expr and failed.

I will check my code again.

Thank you!