Skip to content

Instantly share code, notes, and snippets.

@StephanieSunshine
Created December 7, 2021 11:08
Show Gist options
  • Save StephanieSunshine/504560dff955dc187fb145a6bc73e7e7 to your computer and use it in GitHub Desktop.
Save StephanieSunshine/504560dff955dc187fb145a6bc73e7e7 to your computer and use it in GitHub Desktop.
Rust question
Compiling bubblerust v0.1.0 (/home/stephanie/Projects/Rust/bubblerust)
error[E0308]: mismatched types
--> src/main.rs:17:33
|
17 | println!("{:?}", bubblesort(&list));
| ^^^^^ types differ in mutability
|
= note: expected mutable reference `&mut Vec<u32>`
found reference `&Vec<u32>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `bubblerust`.
To learn more, run the command again with --verbose.
fn bubblesort(l: &mut Vec<u32>) -> &mut Vec<u32> {
(*l).push(100);
l
}
fn main() {
let mut list: Vec<u32> = Vec::new();
list.push(20);
list.push(40);
list.push(10);
list.push(50);
list.push(5);
list.push(1);
println!("{:?}", bubblesort(&list));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment