-2
fn main() {
    first();
    second();
}

fn first() {
    let mut x = 10;
}

fn second() {
    println!("X is {}", x);
}

I want to make first declare the variable inside of that function as mutable. Then the second function should be able to somehow refrence to that variable and mutate it as a global change.

Chayim Friedman
  • 14,050
  • 2
  • 21
  • 36
  • 2
    That is almost certainly a XY problem. Anyway, you should use a `static` mutex. – Chayim Friedman Jun 03 '22 at 00:31
  • https://xyproblem.info/ – Chayim Friedman Jun 03 '22 at 00:33
  • 1
    [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) is when you have a problem X, and you have come up with a solution Y (in your case, Y = global variables), when the *real* problem that needs solved is X and requires a solution other than Y. – Silvio Mayolo Jun 03 '22 at 00:34

0 Answers0