├── .gitignore ├── Makefile ├── README.md └── koans ├── about_arrays.rs ├── about_methods.rs └── about_variables.rs /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.sw[po] 3 | .rustkoans 4 | .DS_Store 5 | 6 | *.sublime-project 7 | *.sublime-workspace 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | build_test: 2 | @echo we will now see where our path takes us. Interprate the error below 3 | @echo correct accordingly 4 | @mkdir -p build 5 | @rustc --test koans/about_${ARGS}.rs --out-dir=build/ 6 | @./build/about_${ARGS} 7 | 8 | setup: 9 | @echo I see you would like some enlightenment, let\'s me prepare things 10 | @echo so we can learn 11 | @touch .rustkoans 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rust Koans 2 | ========== 3 | 4 | The Rust Koans walks you along the path of enlightenment in order to learn Rust. The goal is to learn the Rust language, syntax, structure, and some common functions and libraries. We also teach you culture by basing the koans on tests. Testing is not just something we pay lip service to, but something we live. Testing is essential in your quest to learn and do great things in Rust. 5 | 6 | Setup 7 | ----- 8 | To get started, clone the repo to a location of your choice, change to the ```rust-koans``` folder, and run ```make``` like so: 9 | ``` 10 | $ make setup 11 | ``` 12 | This will prepare a build directory and some other things to make everything awesome (okay it really just makes the build folder, shhh). 13 | 14 | Working through the Koans 15 | ------------------------- 16 | You will work through the koans by running the tests for a given set of problems, then you set about fixing the problems reported by the tests. The Makefile is setup to help you run the tests for a specific file, like so: 17 | ``` 18 | $ make ARGS=about_arrays 19 | ``` 20 | However if you prefer you may build and run the tests yourself with the following: 21 | ``` 22 | $ rustc --test about_arrays.rs --out_dir=build/ 23 | $ ./build/about_arrays.rs 24 | ``` 25 | 26 | Installing Rust 27 | --------------- 28 | 29 | Install the latest [Rust](http://www.rust-lang.org/)! 30 | 31 | -------------------------------------------------------------------------------- /koans/about_arrays.rs: -------------------------------------------------------------------------------- 1 | #[test] 2 | fn test_we_can_get_item_from_array() { 3 | // Create an array 4 | assert!("5" == foo[2]); 5 | } 6 | 7 | #[test] 8 | fn test_we_add_a_new_item_to_an_array() { 9 | let box foo = []; 10 | // Add new items to the array/vector 11 | assert!(foo.len() == 4); 12 | } 13 | 14 | #[test] 15 | fn test_we_can_pop_items_from_list() { 16 | let box foo = ["a", "b", "c"]; 17 | // Pop items from the list 18 | assert!(foo.len() == 2); 19 | assert!(box ["a", "b"] == foo); 20 | } 21 | 22 | #[test] 23 | fn test_that_we_can_slice_arrays() { 24 | let foo = ["a", "b", "c"]; 25 | // Slice the array so you get 1 array item back 26 | assert!(["c"] == bar); 27 | } 28 | 29 | #[test] 30 | fn should_find_the_largest_number_in_an_array(){ 31 | let mut max = 0; 32 | let vec = [1, 5, 6, 8, 2, 3, 4]; 33 | // Use a map to find the largest number 34 | assert!(8 == max); 35 | } 36 | -------------------------------------------------------------------------------- /koans/about_methods.rs: -------------------------------------------------------------------------------- 1 | #[test] 2 | fn should_call_method_and_handle_response(){ 3 | // Return an integer 4 | let foo = sum(4, 5); 5 | assert!(foo == 9); 6 | } 7 | 8 | #[test] 9 | fn should_call_method_and_have_an_implicit_return(){ 10 | /* 11 | Implicit returns have a little magic a thanks to the way 12 | semicolons are handled 13 | */ 14 | 15 | let foo = sum2(4, 5); 16 | assert!(foo == 9); 17 | } -------------------------------------------------------------------------------- /koans/about_variables.rs: -------------------------------------------------------------------------------- 1 | #[test] 2 | fn should_show_variables_are_immutable_by_default(){ 3 | let mut foo = "I like foo"; 4 | foo = "I actually like baz"; 5 | } 6 | 7 | #[test] 8 | fn should_show_a_managed_pointer(){ 9 | // A managed pointer allows us to work with mutable objects 10 | let foo = [1, 2, 3, 4]; 11 | foo.push(5); 12 | } --------------------------------------------------------------------------------