Skip to content

Instantly share code, notes, and snippets.

@GtTmy
Created August 27, 2022 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GtTmy/2aeb066ca36838192c41f5c0331236ef to your computer and use it in GitHub Desktop.
Save GtTmy/2aeb066ca36838192c41f5c0331236ef to your computer and use it in GitHub Desktop.
sliceで配列の一部を関数に渡す
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);
}
@GtTmy
Copy link
Author

GtTmy commented Aug 27, 2022

Standard Error
   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.29s
     Running `target/debug/playground`

Standard Output
[1, 1, 1, 0, 0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment