Created
August 27, 2022 14:52
-
-
Save GtTmy/2aeb066ca36838192c41f5c0331236ef to your computer and use it in GitHub Desktop.
sliceで配列の一部を関数に渡す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn add(a: &mut [i32]) | |
{ | |
for i in a.iter_mut() { | |
*i = *i + 1; | |
} | |
} | |
fn main() | |
{ | |
let mut a = [0; 5]; | |
add(&mut a[0..3]); | |
println!("{:?}", a); | |
} |
Author
GtTmy
commented
Aug 27, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment