right let's try this one again

This commit is contained in:
olivia 2018-11-09 20:31:14 +01:00
parent 850a13e913
commit f7846af7ac
60 changed files with 130 additions and 939 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View file

@ -4,5 +4,6 @@ version = "0.1.0"
authors = ["olivia <olivia@fastmail.com>"]
[dependencies]
quicli = "0.2.0"
ansi_term = "0.11.0"
clap = "2.32.0"
indicatif = "0.9.0"
console = "0.6.2"

View file

@ -1,44 +1,3 @@
# rustlings
A cool thing that is currently in development.
## How it's structured
Ideally, like RubyKoans, all exercises can be run by executing one command, in this case
`cargo run` (most likely). This runs `src/main.rs`, which in turn runs all of the exercises.
Each exercise is contained in a Rust file called `about_<exercise topic>.rs`. A minimal exercise looks
somewhat like this:
```rust
fn exercise_function() {
"hello"
}
mod tests {
use super::*;
pub fn test() {
verify!("REPLACE ME", exercise_function(), "Function description");
}
}
pub fn exec() {
tests::test();
}
```
Each exercise file is supposed to have one `exec` function which gets called by the `main.rs` file.
This function, in turn, calls all individual test functions.
The tests themselves can generally be structured in whatever way is desired, there doesn't have to be a "tests" module, for example. Two macros are provided
for convenience. The `verify` helper function is essentially a specialized `assert_eq!`, but it doesn't panic
if the values mismatch, instead it prints out a helpful error message and keeps going. The
`verify_easy` function is designed as a drop-in replacement for the `verify` function for if the learner needs help solving the exercise. It prints the expected value, too.
This is roughly what the console output for a simple exercise looks right now:
![](https://i.imgur.com/gGgjvLW.png)
Keep in mind that this is a very early draft of how things work. Anything here might be changed
at any time, and this documentation should be updated accordingly.

View file

@ -66,7 +66,7 @@ mod tests {
// One way to handle this is using a `match` statement on
// `item_quantity.parse::<i32>()` where the cases are `Ok(something)` and
// `Err(something)`. This pattern is very common in Rust, though, so there's
// a `try!` macro that does pretty much what you would make that match statement
// a `?` operator that does pretty much what you would make that match statement
// do for you! Take a look at this section of the Error Handling chapter:
// https://doc.rust-lang.org/stable/book/error-handling.html#the-try-macro
// and give it a `try!`
// https://doc.rust-lang.org/stable/book/second-edition/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
// and give it a try!

View file

@ -1,7 +1,7 @@
// errors3.rs
// This is a program that is trying to use a completed version of the
// `total_cost` function from the previous exercise. It's not working though--
// we can't call the `try!` macro in the `main()` function! Why not?
// we can't use the `?` operator in the `main()` function! Why not?
// What should we do instead? Scroll for hints!
use std::num::ParseIntError;
@ -10,7 +10,7 @@ fn main() {
let mut tokens = 100;
let pretend_user_input = "8";
let cost = try!(total_cost(pretend_user_input));
let cost = total_cost(pretend_user_input)?;
if cost > tokens {
println!("You can't afford that many!");
@ -23,7 +23,7 @@ fn main() {
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
let processing_fee = 1;
let cost_per_item = 5;
let qty = try!(item_quantity.parse::<i32>());
let qty = item_quantity.parse::<i32>()?;
Ok(qty * cost_per_item + processing_fee)
}
@ -45,23 +45,18 @@ pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
// Since the `try!` macro returns an `Err` early if the thing it's trying to
// do fails, you can only use the `try!` macro in functions that have a
// Since the `?` operator returns an `Err` early if the thing it's trying to
// do fails, you can only use the `?` operator in functions that have a
// `Result` as their return type.
// The error that you get if you run this code is:
// Hence the error that you get if you run this code is:
// ```
// error: mismatched types:
// expected `()`,
// found `std::result::Result<_, _>`
// error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
// ```
// which is saying that the expected return type of the `main` function is
// the empty tuple, but we tried to return a `Result`-- and that's happening
// in the implementation of `try!`. The `main` function never has a return type,
// so we have to use another way of handling a `Result` within `main`.
// So we have to use another way of handling a `Result` within `main`.
// Decide what we should do if `pretend_user_input` has a string value that does
// not parse to an integer, and implement that instead of calling the `try!`
// macro.
// not parse to an integer, and implement that instead of using the `?`
// operator.

View file

@ -115,21 +115,21 @@ impl error::Error for CreationError {
// Next hint: There are three places in `read_and_validate` that we call a
// function that returns a `Result` (that is, the functions might fail).
// Wrap those calls in a `try!` macro call so that we return immediately from
// Apply the `?` operator on those calls so that we return immediately from
// `read_and_validate` if those function calls fail.
// Another hint: under the hood, the `try!` macro calls `From::from`
// Another hint: under the hood, the `?` operator calls `From::from`
// on the error value to convert it to a boxed trait object, a Box<error::Error>,
// which is polymorphic-- that means that lots of different kinds of errors
// can be returned from the same function because all errors act the same
// since they all implement the `error::Error` trait.
// Check out this section of the book:
// https://doc.rust-lang.org/stable/book/error-handling.html#standard-library-traits-used-for-error-handling
// https://doc.rust-lang.org/stable/book/second-edition/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
// Another another hint: Note that because the `try!` macro returns
// Another another hint: Note that because the `?` operator returns
// the *unwrapped* value in the `Ok` case, if we want to return a `Result` from
// `read_and_validate` for *its* success case, we'll have to rewrap a value
// that we got from the return value of a `try!` call in an `Ok`-- this will
// that we got from the return value of a `?`ed call in an `Ok`-- this will
// look like `Ok(something)`.
// Another another another hint: `Result`s must be "used", that is, you'll

0
old_curriculum/ex1.rs → exercises/ex1.rs Normal file → Executable file
View file

0
old_curriculum/ex2.rs → exercises/ex2.rs Normal file → Executable file
View file

0
old_curriculum/ex3.rs → exercises/ex3.rs Normal file → Executable file
View file

0
old_curriculum/ex4.rs → exercises/ex4.rs Normal file → Executable file
View file

0
old_curriculum/ex5.rs → exercises/ex5.rs Normal file → Executable file
View file

View file

@ -40,5 +40,8 @@ fn square(num: i32) -> i32 {
// This is a really common error that can be fixed by removing one character.
// It happens because Rust distinguishes between expressions and statements: expressions return
// a value and statements don't. We want to return a value from the `square` function, but it
// isn't returning one right now...
// a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language.
// We want to return a value of `i32` type from the `square` function, but it is returning a `()` type...
// They are not the same. There are two solutions:
// 1. Add a `return` ahead of `num * num;`
// 2. remove `;`, make it to be `num * num`

0
old_curriculum/if/if1.rs → exercises/if/if1.rs Normal file → Executable file
View file

View file

View file

View file

View file

View file

View file

View file

@ -1,7 +1,7 @@
// move_semantics1.rs
// Make me compile! Scroll down for hints :)
pub fn main() {
fn main() {
let vec0 = Vec::new();
let vec1 = fill_vec(vec0);

View file

@ -1,7 +1,7 @@
// move_semantics2.rs
// Make me compile without changing line 10! Scroll down for hints :)
pub fn main() {
fn main() {
let vec0 = Vec::new();
let mut vec1 = fill_vec(vec0);

View file

@ -3,7 +3,7 @@
// (no lines with multiple semicolons necessary!)
// Scroll down for hints :)
pub fn main() {
fn main() {
let vec0 = Vec::new();
let mut vec1 = fill_vec(vec0);

View file

@ -3,7 +3,7 @@
// in `fn main`, we instead create it within `fn fill_vec` and transfer the
// freshly created vector from fill_vec to its caller. Scroll for hints!
pub fn main() {
fn main() {
let vec0 = Vec::new();
let mut vec1 = fill_vec(vec0);

View file

@ -39,8 +39,9 @@ fn main() {
// There's a shorthand to initialize Arrays with a certain size that does not
// require you to type in 100 items (but you certainly can if you want!)
// Check out the Primitive Types -> Arrays section of the book:
// https://doc.rust-lang.org/stable/book/second-edition/ch03-02-data-types.html#arrays
// require you to type in 100 items (but you certainly can if you want!).
// For example, you can do:
// let array = ["Are we there yet?"; 10];
// Bonus: what are some other things you could have that would return true
// for `a.len() >= 100`?

View file

@ -38,12 +38,12 @@ fn main() {
// Take a look at the Primitive Types -> Slices section of the book:
// http://doc.rust-lang.org/stable/book/primitive-types.html#slices
// Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book:
// https://doc.rust-lang.org/stable/book/second-edition/ch04-03-slices.html#other-slices
// and use the starting and ending indices of the items in the Array
// that you want to end up in the slice.
// If you're curious why the right hand of the `==` comparison does not
// have an ampersand for a reference since the left hand side is a
// reference, take a look at the Deref coercions chapter:
// http://doc.rust-lang.org/stable/book/deref-coercions.html
// reference, take a look at the Deref coercions section of the book:
// https://doc.rust-lang.org/stable/book/second-edition/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods

View file

@ -0,0 +1,45 @@
// primitive_types5.rs
// Destructure the `cat` tuple so that the println will work.
// Scroll down for hints!
fn main() {
let cat = ("Furry McFurson", 3.5);
let /* your pattern here */ = cat;
println!("{} is {} years old.", name, age);
}
// Take a look at the Data Types -> The Tuple Type section of the book:
// https://doc.rust-lang.org/stable/book/second-edition/ch03-02-data-types.html#the-tuple-type
// Particularly the part about destructuring (second to last example in the section).
// You'll need to make a pattern to bind `name` and `age` to the appropriate parts
// of the tuple. You can do it!!

View file

@ -39,6 +39,7 @@ fn main() {
// While you could use a destructuring `let` for the tuple here, try
// indexing into it instead, as explained here:
// http://doc.rust-lang.org/stable/book/primitive-types.html#tuple-indexing
// indexing into it instead, as explained in the last example of the
// Data Types -> The Tuple Type section of the book:
// https://doc.rust-lang.org/stable/book/second-edition/ch03-02-data-types.html#the-tuple-type
// Now you have another tool in your toolbox!

View file

@ -114,7 +114,8 @@ mod tests {
// Minor hint: In each of the two cases in the match in main, you can create x with either a 'turbofish' or by hinting the type of x to the compiler. You may try both.
// Minor hint: In each of the two cases in the match in main, you can create x with either
// a 'turbofish' or by hinting the type of x to the compiler. You may try both.
@ -142,4 +143,5 @@ mod tests {
// Major hint: Have a look at the Iter trait and at the explanation of its collect function. Especially the part about Result is interesting.
// Major hint: Have a look at the Iter trait and at the explanation of its collect function.
// Especially the part about Result is interesting.

View file

View file

View file

View file

View file

View file

View file

View file

@ -45,7 +45,7 @@ fn main() {
// to **immutable** data. But we want to *change* the number of `jobs_completed`
// so we'll need to also use another type that will only allow one thread to
// mutate the data at a time. Take a look at this section of the book:
// https://doc.rust-lang.org/stable/book/concurrency.html#safe-shared-mutable-state
// https://doc.rust-lang.org/stable/book/second-edition/ch16-03-shared-state.html#atomic-reference-counting-with-arct
// and keep scrolling if you'd like more hints :)

View file

@ -1,19 +0,0 @@
language: rust
branches:
only:
- master
cache:
cargo: true
script:
- cargo run --bin generate_readme
- git config user.name "Carol (Nichols || Goulding)"
- git config user.email "carol.nichols@gmail.com"
- git commit -am "Regenerate README" && git remote add upstream "https://$GH_TOKEN@github.com/carols10cents/rustlings.git" && git push -q upstream HEAD:master > /dev/null 2>&1 || true
notifications:
email:
on_success: never

View file

@ -1,456 +0,0 @@
[[package]]
name = "aho-corasick"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ansi_term"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "atty"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
version = "2.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "encoding"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-japanese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-korean"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-simpchinese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-singlebyte"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-tradchinese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding_index_tests"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "handlebars"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pest_derive 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "idna"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "matches"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memchr"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "percent-encoding"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pest"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pest_derive"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"pest 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "prlink"
version = "0.1.0"
source = "git+https://github.com/btbytes/prlink#f0536ed3b322072d65c42da2fc2a817b77d77308"
dependencies = [
"clap 2.30.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quick-error"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_syscall"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustlings"
version = "0.1.0"
dependencies = [
"handlebars 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"prlink 0.1.0 (git+https://github.com/btbytes/prlink)",
"serde_json 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_json"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strsim"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "0.11.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-bidi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-normalization"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-width"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "url"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "utf8-ranges"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4"
"checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455"
"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
"checksum clap 2.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1c07b9257a00f3fc93b7f3c417fc15607ec7a56823bc2c37ec744e266387de5b"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
"checksum encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
"checksum encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81"
"checksum encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7"
"checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum handlebars 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07af2ff31f66f39a5c8b8b8a5dc02734a453110146763e3a2323f4931a915a76"
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
"checksum libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)" = "56aebce561378d99a0bb578f8cb15b6114d2a1814a6c7949bbe646d968bb4fa9"
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum num-traits 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3c2bd9b9d21e48e956b763c9f37134dc62d9e95da6edb3f672cacb6caf3cd3"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum pest 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0fce5d8b5cc33983fc74f78ad552b5522ab41442c4ca91606e4236eb4b5ceefc"
"checksum pest_derive 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6453faedc5c9980a3c278f28b1df33344a79cc6d4a2fd96e2b56288374dc822a"
"checksum prlink 0.1.0 (git+https://github.com/btbytes/prlink)" = "<none>"
"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "5be5347bde0c48cfd8c3fdc0766cdfe9d8a755ef84d620d6794c778c91de8b2b"
"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e"
"checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526"
"checksum serde_json 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "57781ed845b8e742fc2bf306aba8e3b408fe8c366b900e3769fbc39f49eb8b39"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693"
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -1,9 +0,0 @@
[package]
name = "rustlings"
version = "0.1.0"
authors = ["Carol (Nichols || Goulding) <carol.nichols@gmail.com>"]
[dependencies]
handlebars = "0.32.0"
serde_json = "1.0.10"
prlink = { git = "https://github.com/btbytes/prlink" }

View file

@ -1,190 +0,0 @@
<!--
{{ autogenerated_notice }}
-->
# rustlings
Small exercises to get you used to reading and writing Rust code. Includes practice reading and
responding to compiler messages!
This repo is very much the smallest thing that could possibly work :)
## To do these exercises
Thanks to [btbytes'](https://twitter.com/btbytes) [prlinks](https://github.com/btbytes/prlink), you
can now click on the links below to load the exercises in the rust playground!
There are infinite correct answers-- the exercises are sometimes left very open-ended. Scroll down
in the playground to find comments that have hints.
If you need more help or would like to compare solutions, you can ask in [#rust-beginners on
irc.mozilla.org](https://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-beginners ), the
[user forum](https://users.rust-lang.org/), or [the subreddit](https://reddit.com/r/rust). If an
exercise could be improved in any way, please [create an
issue](https://github.com/carols10cents/rustlings/issues/new) or submit a pull request!
### Variable bindings
[Relevant chapter in The Rust Programming
Language](https://doc.rust-lang.org/book/second-edition/ch03-01-variables-and-mutability.html)
{{ playground_link "variables/variables1.rs" }}
{{ playground_link "variables/variables2.rs" }}
{{ playground_link "variables/variables3.rs" }}
{{ playground_link "variables/variables4.rs" }}
### Functions
[Relevant chapter in The Rust Programming
Language](https://doc.rust-lang.org/book/second-edition/ch03-03-how-functions-work.html)
{{ playground_link "functions/functions1.rs" }}
{{ playground_link "functions/functions2.rs" }}
{{ playground_link "functions/functions3.rs" }}
{{ playground_link "functions/functions4.rs" }}
{{ playground_link "functions/functions5.rs" }}
### Primitive types
[Relevant chapter in The Rust Programming
Language](https://doc.rust-lang.org/book/second-edition/ch03-02-data-types.html)
{{ playground_link "primitive_types/primitive_types1.rs" }}
{{ playground_link "primitive_types/primitive_types2.rs" }}
{{ playground_link "primitive_types/primitive_types3.rs" }}
{{ playground_link "primitive_types/primitive_types4.rs" }}
{{ playground_link "primitive_types/primitive_types5.rs" }}
{{ playground_link "primitive_types/primitive_types6.rs" }}
### Tests
Going out of order from the book to cover tests-- many of the following exercises will ask you to
make tests pass!
[Relevant chapter in The Rust Programming
Language](https://doc.rust-lang.org/book/second-edition/ch11-01-writing-tests.html)
{{ playground_link "tests/tests1.rs" }}
{{ playground_link "tests/tests2.rs" }}
{{ playground_link "tests/tests3.rs" }}
{{ playground_link "tests/tests4.rs" }}
### If
[Relevant chapter in The Rust Programming
Language](https://doc.rust-lang.org/book/second-edition/ch03-05-control-flow.html)
{{ playground_link "if/if1.rs" }}
### Strings
[Relevant chapter in The Rust Programming
Language](https://doc.rust-lang.org/book/second-edition/ch08-02-strings.html)
{{ playground_link "strings/strings1.rs" }}
{{ playground_link "strings/strings2.rs" }}
{{ playground_link "strings/strings3.rs" }}
### Move semantics
These exercises are adapted from [pnkfelix]()'s [Rust
Tutorial](https://pnkfelix.github.io/rust-examples-icfp2014/) -- thank you Felix!!!
Relevant chapters in the book:
- [Ownership](https://doc.rust-lang.org/book/second-edition/ch04-01-what-is-ownership.html)
- [References and borrowing](https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html)
Note that the exercises in this section may look similar to each other but they are subtly
different :)
{{ playground_link "move_semantics/move_semantics1.rs" }}
{{ playground_link "move_semantics/move_semantics2.rs" }}
{{ playground_link "move_semantics/move_semantics3.rs" }}
{{ playground_link "move_semantics/move_semantics4.rs" }}
### Modules
[Relevant chapter in The Rust Programming
Language](https://doc.rust-lang.org/book/second-edition/ch07-01-mod-and-the-filesystem.html)
{{ playground_link "modules/modules1.rs" }}
{{ playground_link "modules/modules2.rs" }}
### Macros
Check out:
- [The Macros section of the first edition of the book
book](https://doc.rust-lang.org/book/first-edition/macros.html)
- [The Macros appendix of the second edition of the
book](https://doc.rust-lang.org/book/second-edition/appendix-04-macros.html)
- [The Little Book of Rust Macros](https://danielkeep.github.io/tlborm/book/index.html)
{{ playground_link "macros/macros1.rs" }}
{{ playground_link "macros/macros2.rs" }}
{{ playground_link "macros/macros3.rs" }}
{{ playground_link "macros/macros4.rs" }}
### Error Handling
The [Error
Handling](https://doc.rust-lang.org/book/second-edition/ch09-02-recoverable-errors-with-result.html)
and [Generics](https://doc.rust-lang.org/book/second-edition/ch10-01-syntax.html) sections are
relevant.
{{ playground_link "error_handling/option1.rs" }}
{{ playground_link "error_handling/result1.rs" }}
{{ playground_link "error_handling/errors1.rs" }}
{{ playground_link "error_handling/errors2.rs" }}
{{ playground_link "error_handling/errors3.rs" }}
{{ playground_link "error_handling/errorsn.rs" }}
### Standard library types
#### `Arc`
The [Concurrency](https://doc.rust-lang.org/book/second-edition/ch16-03-shared-state.html) section
is relevant.
{{ playground_link "standard_library_types/arc1.rs" }}
#### Iterators
Do not adjust your monitors-- iterators 1 and 2 are indeed missing. Iterator 3 is a bit challenging
so we're leaving space for some exercises to lead up to it!
Check out the [Iterators chapter of the
book](https://doc.rust-lang.org/book/second-edition/ch13-02-iterators.html) and the [Iterator
docs](https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html).
{{ playground_link "standard_library_types/iterator3.rs" }}
{{ playground_link "standard_library_types/iterators4.rs" }}
### Threads
See [the Dining Philosophers
example](https://doc.rust-lang.org/1.4.0/book/first-edition/dining-philosophers.html) and the
[Concurrency Chapter](https://doc.rust-lang.org/book/second-edition/ch16-01-threads.html) from the
book.
{{ playground_link "threads/threads1.rs" }}
### Uncategorized
A few exercises based on things I've encountered or had trouble with getting used to.
{{ playground_link "ex1.rs" }}
{{ playground_link "ex2.rs" }}
{{ playground_link "ex3.rs" }}
{{ playground_link "ex4.rs" }}
{{ playground_link "ex5.rs" }}
## To help with this repo/TODO list
* File issues for problems or suggestions!
* Contribute more exercises! Anything that took you time to get used to, or that you had trouble
with, or that deserves practice would be a good exercise!
* How could the process of doing these exercises work better? This is an open-ended question :) Are
the playground links good enough? Are there ways that we could make going to the next exercise
easier without forking the playground??

View file

@ -1,45 +0,0 @@
// primitive_types5.rs
// Destructure the `cat` tuple so that the println will work.
// Scroll down for hints!
fn main() {
let cat = ("Furry McFurson", 3.5);
let /* your pattern here */ = cat;
println!("{} is {} years old.", name, age);
}
// Take a look at the Primitive Types -> Tuples section of the book:
// http://doc.rust-lang.org/stable/book/primitive-types.html#tuples
// Particularly the part about "destructuring lets". You'll need to
// make a pattern to bind `name` and `age` to the appropriate parts
// of the tuple. You can do it!!

View file

@ -1,49 +0,0 @@
// This script reads README-template.md and generates the playground links
// from the Rust source files in the various directories.
// To add a new exercise, add it to the appropriate place in README-template.md
// and then make sure to recompile this script (because the template gets
// included at compile time and then run it to generate a new version of
// README.md.
extern crate handlebars;
extern crate prlink;
#[macro_use]
extern crate serde_json;
use handlebars::{Handlebars, Helper, RenderContext, RenderError};
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
fn main() {
let mut template_file = File::open("README-template.hbs").unwrap();
let mut template = String::new();
template_file.read_to_string(&mut template).unwrap();
let autogenerated_notice = "This file was autogenerated by the script in src/bin/generate_readme.rs.
Please edit either the script or the template in README-template.md in
order to make changes here rather than committing the changes directly.";
let mut generated_readme = File::create("README.md").unwrap();
let mut hbs = Handlebars::new();
hbs.register_helper("playground_link", Box::new(playground_link_helper));
write!(
generated_readme,
"{}",
hbs.render_template(
&template,
&json!({ "autogenerated_notice": autogenerated_notice }),
).unwrap()
).unwrap();
}
fn playground_link_helper(h: &Helper, _: &Handlebars, rc: &mut RenderContext) -> Result<(), RenderError> {
let filename = PathBuf::from(h.param(0).unwrap().value().as_str().unwrap());
let link = prlink::linkify_file(&filename);
rc.writer.write(link.into_bytes().as_ref())?;
Ok(())
}

View file

@ -1,38 +0,0 @@
use helpers::*;
// Variables in Rust are defined using the "let" keyword. Like this:
fn exercise_one() {
let x = 5;
verify(5, x);
// ^ ^
// | |
// What's The variable
// in it name
}
// Try to replace the "0" with the value of the variable, then run
// "cargo run" and see if it was correct!
// Here's a more complicated example:
fn guess_me() -> &'static str {
let x = 10;
if x == 10 {
return "Ten!";
} else {
return "Not ten!";
}
}
fn exercise_two() {
let result = guess_me();
verify("REPLACE ME", result);
}
pub fn exec() {
title("Variables: Exercise 1");
exercise_one();
title("Variables: Exercise 2");
exercise_two();
}

View file

@ -1,33 +0,0 @@
use ansi_term::Color::{Green, Red, Yellow};
use std::fmt::Display;
pub fn verify<T: PartialEq + Display>(left: T, right: T) {
if left == right {
println!("{} {} == {}", Green.bold().paint("PASS"), left, right);
} else {
println!(
"{} You submitted {}, but that's not correct!",
Red.bold().paint("FAIL"),
left
);
println!(" Please correct your code to make this test pass!");
}
}
pub fn verify_easy<T: PartialEq + Display>(left: T, right: T) {
if left == right {
println!("{} {} == {}", Green.bold().paint("PASS"), left, right);
} else {
println!(
"{} You submitted {}, but that's not correct!",
Red.bold().paint("FAIL"),
left
);
println!(" Expected: {}", right);
println!(" Please correct your code to make this test pass!");
}
}
pub fn title(s: &str) {
println!("{} {}", Yellow.bold().paint("RUN"), s);
}

View file

@ -1,21 +1,44 @@
#[macro_use]
extern crate quicli;
extern crate ansi_term;
extern crate clap;
extern crate indicatif;
extern crate console;
use ansi_term::Color::Yellow;
use quicli::prelude::*;
use clap::{App, SubCommand};
use indicatif::{ProgressBar};
use console::{style, Emoji};
use std::process::Command;
mod helpers;
mod about_variables;
fn main() {
let matches = App::new("r2")
.version(crate_version!())
.author("Olivia Hugger")
.about("Test")
.subcommand(SubCommand::with_name("verify").alias("v"))
.get_matches();
#[derive(Debug, StructOpt)]
struct Cli {
exercise: Option<String>,
if let Some(_) = matches.subcommand_matches("verify") {
execute("exercises/ex1.rs");
execute("exercises/ex2.rs");
execute("exercises/ex3.rs");
execute("exercises/ex4.rs");
execute("exercises/ex5.rs");
}
}
main!(|args: Cli| if let Some(e) = args.exercise {
println!("selected {}", e);
} else {
println!("Welcome to {}!\n", Yellow.paint("Rustlings"));
about_variables::exec();
});
fn execute(filename: &str) {
let bar = ProgressBar::new_spinner();
bar.set_message(format!("Compiling {}...", filename).as_str());
bar.enable_steady_tick(100);
let compilecmd = Command::new("rustc")
.args(&[filename, "-o", "temp"])
.output()
.expect("fail");
bar.finish_and_clear();
if compilecmd.status.success() {
println!("{} Successfully compiled {}!", Emoji("", ""), style(filename).italic());
} else {
println!("{} Compilation of {} failed! Compiler error message:\n", Emoji("⚠️ ", "!"), style(filename).italic());
println!("{}", String::from_utf8_lossy(&compilecmd.stderr));
std::process::exit(1);
}
}