mirror of https://github.com/rust-lang/rustlings
Clean up and unify exercises
parent
cb9f1ac9ce
commit
2f810a4da6
@ -1,8 +1,3 @@
|
||||
// functions1.rs
|
||||
//
|
||||
// Execute `rustlings hint functions1` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
fn main() {
|
||||
call_me();
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
// primitive_types4.rs
|
||||
//
|
||||
// Get a slice out of Array a where the ??? is so that the test passes.
|
||||
//
|
||||
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slice_out_of_array() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn slice_out_of_array() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
|
||||
let nice_slice = ???
|
||||
|
||||
assert_eq!([2, 3, 4], nice_slice)
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
// primitive_types6.rs
|
||||
//
|
||||
// Use a tuple index to access the second element of `numbers`. You can put the
|
||||
// expression for the second element where ??? is so that the test passes.
|
||||
//
|
||||
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indexing_tuple() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn indexing_tuple() {
|
||||
let numbers = (1, 2, 3);
|
||||
// Replace below ??? with the tuple indexing syntax.
|
||||
let second = ???;
|
||||
|
||||
assert_eq!(2, second,
|
||||
"This is not the 2nd number in the tuple!")
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,25 @@
|
||||
// move_semantics1.rs
|
||||
//
|
||||
// Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
let vec = vec;
|
||||
|
||||
#[test]
|
||||
fn main() {
|
||||
let vec0 = vec![22, 44, 66];
|
||||
vec.push(88);
|
||||
|
||||
let vec1 = fill_vec(vec0);
|
||||
vec
|
||||
}
|
||||
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
let vec = vec;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
vec.push(88);
|
||||
#[test]
|
||||
fn move_semantics1() {
|
||||
let vec0 = vec![22, 44, 66];
|
||||
|
||||
vec
|
||||
let vec1 = fill_vec(vec0);
|
||||
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,28 @@
|
||||
// move_semantics2.rs
|
||||
//
|
||||
// Make the test pass by finding a way to keep both Vecs separate!
|
||||
//
|
||||
// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
#[test]
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
let mut vec = vec;
|
||||
|
||||
vec.push(88);
|
||||
|
||||
vec
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn move_semantics2() {
|
||||
let vec0 = vec![22, 44, 66];
|
||||
|
||||
let vec1 = fill_vec(vec0);
|
||||
|
||||
assert_eq!(vec0, vec![22, 44, 66]);
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
let mut vec = vec;
|
||||
|
||||
vec.push(88);
|
||||
|
||||
vec
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,26 @@
|
||||
// move_semantics3.rs
|
||||
//
|
||||
// Make me compile without adding new lines -- just changing existing lines! (no
|
||||
// lines with multiple semicolons necessary!)
|
||||
//
|
||||
// Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
#[test]
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
vec.push(88);
|
||||
|
||||
vec
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn move_semantics3() {
|
||||
let vec0 = vec![22, 44, 66];
|
||||
|
||||
let vec1 = fill_vec(vec0);
|
||||
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
vec.push(88);
|
||||
|
||||
vec
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,21 @@
|
||||
// move_semantics5.rs
|
||||
//
|
||||
// Make me compile only by reordering the lines in `main()`, but without adding,
|
||||
// Make me compile only by reordering the lines in the test, but without adding,
|
||||
// changing or removing any of them.
|
||||
//
|
||||
// Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
#[test]
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn move_semantics5() {
|
||||
let mut x = 100;
|
||||
let y = &mut x;
|
||||
let z = &mut x;
|
||||
*y += 100;
|
||||
*z += 1000;
|
||||
assert_eq!(x, 1200);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue