You've declared a completely new variable called b that you never use. Defining this does absolutely nothing to change the contents of the b parameter. I'm not sure why you're trying to use let here when a simple assignment works just fine:
Thanks for your help. I thought we need to use move semantics to change the value of parameter b. I am not sure if using direct assignment would lead to dangle pointers.
You cannot create dangling pointers in Rust without using unsafe code. A major selling point of Rust is that you don't have to worry about this.
let statements have nothing to do with move semantics. They just define variables.
You're not changing b, you're changing the thing b points to.
You don't ever need to distinguish between move and copy semantics when you're using something. If you try to copy something that can't be copied, you'll get a compile error. If you try to move something which cannot be moved (because there are existing pointers to it), you'll get a compile error. Again, this is not something you ever need to worry about.
By default, unless you specify mut, the array b cannot be changed in the function. So you could remove the mut from the signature of the function, and it would not be allowed to change the array.
If you still want the copy (to be able to make changes), types which support this type of copying implement Clone, so you could write let newArray = b.clone();. This would make a copy of b, and changes to it would not affect b.
Use &mut only when you want to allow functions to change the referenced values. Use & to disallow changing of the referenced data. Don't use & when you want a copy.
Compiling playground v0.0.1 (/playground)
error[E0594]: cannot assign to `b[..]`, as `b` is not declared as mutable
--> src/main.rs:4:9
|
2 | fn func(b: [i32;3], num: i32) -> [i32;3]{
| - help: consider changing this to be mutable: `mut b`
3 | if num > 10 {
4 | b[0] = num;
| ^^^^^^^^^^ cannot assign
error[E0384]: cannot assign to immutable argument `b`
--> src/main.rs:7:9
|
2 | fn func(b: [i32;3], num: i32) -> [i32;3]{
| - help: make this binding mutable: `mut b`
...
7 | b = c;
| ^^^^^ cannot assign to immutable argument
error: aborting due to 2 previous errors
Some errors occurred: E0384, E0594.
For more information about an error, try `rustc --explain E0384`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
It's worth also talking about Copy. Some types, like the primitive numeric types, are marked with Copy - this makes it so that they are copied when not using &, as @kornel says. This happens instead of 'moving' the value from one owner to another.
Here is a link to the playground, where I've made the change I suggested. Read it, and see if you understand what I did. If not, feel free to keep asking here.
Because arrays inherit their Copy- and Clone- ability from the type they're declared from, @kornel's solution of simply using an ownership-transferring assignment does work here. However, it might not, depending on what is in the array. My solution might not, either - if they type is not Clone-able, then you simply cannot make a copy so simply.
For a more detailed look at what we're talking about, you may want to read The Book - Especially the chapter here talking about borrowing and ownership. They're pretty important in rust, and one of the things rust does differently from most languages