mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
Merge branch 'main' into dameng
This commit is contained in:
commit
ae2ebffe6a
@ -2073,6 +2073,69 @@
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "nmay231",
|
||||
"name": "Noah",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/35386821?v=4",
|
||||
"profile": "https://github.com/nmay231",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "rb5014",
|
||||
"name": "rb5014",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/105397317?v=4",
|
||||
"profile": "https://github.com/rb5014",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "deedy5",
|
||||
"name": "deedy5",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/65482418?v=4",
|
||||
"profile": "https://github.com/deedy5",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "lionel-rowe",
|
||||
"name": "lionel-rowe",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/26078826?v=4",
|
||||
"profile": "https://github.com/lionel-rowe",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Ben2917",
|
||||
"name": "Ben",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/10279994?v=4",
|
||||
"profile": "https://github.com/Ben2917",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "b1ue64",
|
||||
"name": "b1ue64",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/77976308?v=4",
|
||||
"profile": "https://github.com/b1ue64",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "lazywalker",
|
||||
"name": "lazywalker",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/53956?v=4",
|
||||
"profile": "https://github.com/lazywalker",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 8,
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -11,3 +11,7 @@ rust-project.json
|
||||
!.vscode/extensions.json
|
||||
*.iml
|
||||
*.o
|
||||
public/
|
||||
|
||||
# Local Netlify folder
|
||||
.netlify
|
||||
|
||||
@ -294,6 +294,15 @@ authors.
|
||||
<td align="center" valign="top" width="12.5%"><a href="http://www.alangerber.us"><img src="https://avatars.githubusercontent.com/u/201313?v=4?s=100" width="100px;" alt="Alan Gerber"/><br /><sub><b>Alan Gerber</b></sub></a><br /><a href="#content-akgerber" title="Content">🖋</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="http://esotuvaka.github.io"><img src="https://avatars.githubusercontent.com/u/104941850?v=4?s=100" width="100px;" alt="Eric"/><br /><sub><b>Eric</b></sub></a><br /><a href="#content-esotuvaka" title="Content">🖋</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/az0977776"><img src="https://avatars.githubusercontent.com/u/9172038?v=4?s=100" width="100px;" alt="Aaron Wang"/><br /><sub><b>Aaron Wang</b></sub></a><br /><a href="#content-az0977776" title="Content">🖋</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/nmay231"><img src="https://avatars.githubusercontent.com/u/35386821?v=4?s=100" width="100px;" alt="Noah"/><br /><sub><b>Noah</b></sub></a><br /><a href="#content-nmay231" title="Content">🖋</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/rb5014"><img src="https://avatars.githubusercontent.com/u/105397317?v=4?s=100" width="100px;" alt="rb5014"/><br /><sub><b>rb5014</b></sub></a><br /><a href="#content-rb5014" title="Content">🖋</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/deedy5"><img src="https://avatars.githubusercontent.com/u/65482418?v=4?s=100" width="100px;" alt="deedy5"/><br /><sub><b>deedy5</b></sub></a><br /><a href="#content-deedy5" title="Content">🖋</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/lionel-rowe"><img src="https://avatars.githubusercontent.com/u/26078826?v=4?s=100" width="100px;" alt="lionel-rowe"/><br /><sub><b>lionel-rowe</b></sub></a><br /><a href="#content-lionel-rowe" title="Content">🖋</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/Ben2917"><img src="https://avatars.githubusercontent.com/u/10279994?v=4?s=100" width="100px;" alt="Ben"/><br /><sub><b>Ben</b></sub></a><br /><a href="#content-Ben2917" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/b1ue64"><img src="https://avatars.githubusercontent.com/u/77976308?v=4?s=100" width="100px;" alt="b1ue64"/><br /><sub><b>b1ue64</b></sub></a><br /><a href="#content-b1ue64" title="Content">🖋</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/lazywalker"><img src="https://avatars.githubusercontent.com/u/53956?v=4?s=100" width="100px;" alt="lazywalker"/><br /><sub><b>lazywalker</b></sub></a><br /><a href="#content-lazywalker" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
42
CHANGELOG.md
42
CHANGELOG.md
@ -1,3 +1,45 @@
|
||||
<a name="5.5.1"></a>
|
||||
## 5.5.1 (2023-05-17)
|
||||
|
||||
#### Fixed
|
||||
|
||||
- Reverted `rust-project.json` path generation due to an upstream `rust-analyzer` fix.
|
||||
|
||||
<a name="5.5.0"></a>
|
||||
## 5.5.0 (2023-05-17)
|
||||
|
||||
#### Added
|
||||
|
||||
- `strings2`: Added a reference to the book chapter for reference conversion
|
||||
- `lifetimes`: Added a link to the lifetimekata project
|
||||
- Added a new `tests4` exercises, which teaches about testing for panics
|
||||
- Added a `!` prefix command to watch mode that runs an external command
|
||||
- Added a `--success-hints` option to watch mode that shows hints on exercise success
|
||||
|
||||
#### Changed
|
||||
|
||||
- `vecs2`: Renamed iterator variable bindings for clarify
|
||||
- `lifetimes`: Changed order of book references
|
||||
- `hashmaps2`: Clarified instructions in the todo block
|
||||
- Moved lifetime exercises before test exercises (via the recommended book ordering)
|
||||
- `options2`: Improved tests for layering options
|
||||
- `modules2`: Added more information to the hint
|
||||
|
||||
#### Fixed
|
||||
|
||||
- `errors2`: Corrected a comment wording
|
||||
- `iterators2`: Fixed a spelling mistake in the hint text
|
||||
- `variables`: Wrapped the mut keyword with backticks for readability
|
||||
- `move_semantics2`: Removed references to line numbers
|
||||
- `cow1`: Clarified the `owned_no_mutation` comments
|
||||
- `options3`: Changed exercise to panic when no match is found
|
||||
- `rustlings lsp` now generates absolute paths, which should fix VSCode `rust-analyzer` usage on Windows
|
||||
|
||||
#### Housekeeping
|
||||
|
||||
- Added a markdown linter to run on GitHub actions
|
||||
- Split quick installation section into two code blocks
|
||||
|
||||
<a name="5.4.1"></a>
|
||||
## 5.4.1 (2023-03-10)
|
||||
|
||||
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -441,7 +441,7 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "rustlings"
|
||||
version = "5.4.1"
|
||||
version = "5.5.1"
|
||||
dependencies = [
|
||||
"argh",
|
||||
"assert_cmd",
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
[package]
|
||||
name = "rustlings"
|
||||
version = "5.4.1"
|
||||
description = "Small exercises to get you used to reading and writing Rust code!"
|
||||
version = "5.5.1"
|
||||
authors = [
|
||||
"Liv <mokou@fastmail.com>",
|
||||
"Carol (Nichols || Goulding) <carol.nichols@gmail.com>",
|
||||
|
||||
12
README.md
12
README.md
@ -1,5 +1,9 @@
|
||||
<div class="oranda-hide">
|
||||
|
||||
# rustlings 🦀❤️
|
||||
|
||||
</div>
|
||||
|
||||
Greetings and welcome to `rustlings`. This project contains small exercises to get you used to reading and writing Rust code. This includes reading and responding to compiler messages!
|
||||
|
||||
_...looking for the old, web-based version of Rustlings? Try [here](https://github.com/rust-lang/rustlings/tree/rustlings-1)_
|
||||
@ -36,8 +40,8 @@ This will install Rustlings and give you access to the `rustlings` command. Run
|
||||
Basically: Clone the repository at the latest tag, finally run `nix develop` or `nix-shell`.
|
||||
|
||||
```bash
|
||||
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.4.1)
|
||||
git clone -b 5.4.1 --depth 1 https://github.com/rust-lang/rustlings
|
||||
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.5.1)
|
||||
git clone -b 5.5.1 --depth 1 https://github.com/rust-lang/rustlings
|
||||
cd rustlings
|
||||
# if nix version > 2.3
|
||||
nix develop
|
||||
@ -74,8 +78,8 @@ If you get a permission denied message, you might have to exclude the directory
|
||||
Basically: Clone the repository at the latest tag, run `cargo install --path .`.
|
||||
|
||||
```bash
|
||||
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.4.1)
|
||||
git clone -b 5.4.1 --depth 1 https://github.com/rust-lang/rustlings
|
||||
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.5.1)
|
||||
git clone -b 5.5.1 --depth 1 https://github.com/rust-lang/rustlings
|
||||
cd rustlings
|
||||
cargo install --force --path .
|
||||
```
|
||||
|
||||
@ -65,12 +65,27 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_equals_for() {
|
||||
fn count_some() {
|
||||
let map = get_map();
|
||||
assert_eq!(
|
||||
count_for(&map, Progress::Complete),
|
||||
count_iterator(&map, Progress::Complete)
|
||||
);
|
||||
assert_eq!(1, count_iterator(&map, Progress::Some));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_none() {
|
||||
let map = get_map();
|
||||
assert_eq!(2, count_iterator(&map, Progress::None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_complete_equals_for() {
|
||||
let map = get_map();
|
||||
let progress_states = vec![Progress::Complete, Progress::Some, Progress::None];
|
||||
for progress_state in progress_states {
|
||||
assert_eq!(
|
||||
count_for(&map, progress_state),
|
||||
count_iterator(&map, progress_state)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -83,12 +98,28 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_collection_equals_for() {
|
||||
fn count_collection_some() {
|
||||
let collection = get_vec_map();
|
||||
assert_eq!(
|
||||
count_collection_for(&collection, Progress::Complete),
|
||||
count_collection_iterator(&collection, Progress::Complete)
|
||||
);
|
||||
assert_eq!(1, count_collection_iterator(&collection, Progress::Some));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_collection_none() {
|
||||
let collection = get_vec_map();
|
||||
assert_eq!(4, count_collection_iterator(&collection, Progress::None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_collection_equals_for() {
|
||||
let progress_states = vec![Progress::Complete, Progress::Some, Progress::None];
|
||||
let collection = get_vec_map();
|
||||
|
||||
for progress_state in progress_states {
|
||||
assert_eq!(
|
||||
count_collection_for(&collection, progress_state),
|
||||
count_collection_iterator(&collection, progress_state)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_map() -> HashMap<String, Progress> {
|
||||
|
||||
@ -17,12 +17,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn layered_option() {
|
||||
let mut range = 10;
|
||||
let mut optional_integers: Vec<Option<i8>> = Vec::new();
|
||||
for i in 0..(range + 1) {
|
||||
let range = 10;
|
||||
let mut optional_integers: Vec<Option<i8>> = vec![None];
|
||||
|
||||
for i in 1..(range + 1) {
|
||||
optional_integers.push(Some(i));
|
||||
}
|
||||
|
||||
let mut cursor = range;
|
||||
|
||||
// TODO: make this a while let statement - remember that vector.pop also adds another layer of Option<T>
|
||||
// You can stack `Option<T>`'s into while let and if let
|
||||
|
||||
@ -30,5 +33,7 @@ mod tests {
|
||||
assert_eq!(integer, range);
|
||||
range -= 1;
|
||||
}
|
||||
|
||||
assert_eq!(cursor, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ fn main() {
|
||||
|
||||
match &y {
|
||||
Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y),
|
||||
_ => println!("no match"),
|
||||
_ => panic!("no match!"),
|
||||
}
|
||||
y; // Fix without deleting this line.
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
rustlings =
|
||||
pkgs.rustPlatform.buildRustPackage {
|
||||
name = "rustlings";
|
||||
version = "5.4.1";
|
||||
version = "5.5.1";
|
||||
|
||||
buildInputs = cargoBuildInputs;
|
||||
|
||||
|
||||
@ -478,7 +478,8 @@ hint = """
|
||||
The delicious_snacks module is trying to present an external interface that is
|
||||
different than its internal structure (the `fruits` and `veggies` modules and
|
||||
associated constants). Complete the `use` statements to fit the uses in main and
|
||||
find the one keyword missing for both constants."""
|
||||
find the one keyword missing for both constants.
|
||||
Learn more at https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html#re-exporting-names-with-pub-use"""
|
||||
|
||||
[[exercises]]
|
||||
name = "modules3"
|
||||
@ -896,9 +897,6 @@ hint = """
|
||||
The documentation for the std::iter::Iterator trait contains numerous methods
|
||||
that would be helpful here.
|
||||
|
||||
Return 0 from count_collection_iterator to make the code compile in order to
|
||||
test count_iterator.
|
||||
|
||||
The collection variable in count_collection_iterator is a slice of HashMaps. It
|
||||
needs to be converted into an iterator in order to use the iterator methods.
|
||||
|
||||
|
||||
10
oranda.json
Normal file
10
oranda.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"homepage": "https://rustlings.cool",
|
||||
"repository": "https://github.com/rust-lang/rustlings",
|
||||
"analytics": {
|
||||
"plausible": {
|
||||
"domain": "rustlings.cool"
|
||||
}
|
||||
},
|
||||
"changelog": false
|
||||
}
|
||||
32
src/main.rs
32
src/main.rs
@ -26,7 +26,7 @@ mod run;
|
||||
mod verify;
|
||||
|
||||
// In sync with crate version
|
||||
const VERSION: &str = "5.4.1";
|
||||
const VERSION: &str = "5.5.1";
|
||||
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code
|
||||
@ -61,7 +61,11 @@ struct VerifyArgs {}
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
#[argh(subcommand, name = "watch")]
|
||||
/// Reruns `verify` when files were edited
|
||||
struct WatchArgs {}
|
||||
struct WatchArgs {
|
||||
/// show hints on success
|
||||
#[argh(switch)]
|
||||
success_hints: bool,
|
||||
}
|
||||
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
#[argh(subcommand, name = "run")]
|
||||
@ -229,7 +233,7 @@ fn main() {
|
||||
}
|
||||
|
||||
Subcommands::Verify(_subargs) => {
|
||||
verify(&exercises, (0, exercises.len()), verbose)
|
||||
verify(&exercises, (0, exercises.len()), verbose, false)
|
||||
.unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
@ -252,7 +256,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
Subcommands::Watch(_subargs) => match watch(&exercises, verbose) {
|
||||
Subcommands::Watch(_subargs) => match watch(&exercises, verbose, _subargs.success_hints) {
|
||||
Err(e) => {
|
||||
println!(
|
||||
"Error: Could not watch your progress. Error message was {:?}.",
|
||||
@ -348,7 +352,11 @@ enum WatchStatus {
|
||||
Unfinished,
|
||||
}
|
||||
|
||||
fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
fn watch(
|
||||
exercises: &[Exercise],
|
||||
verbose: bool,
|
||||
success_hints: bool,
|
||||
) -> notify::Result<WatchStatus> {
|
||||
/* Clears the terminal with an ANSI escape code.
|
||||
Works in UNIX and newer Windows terminals. */
|
||||
fn clear_screen() {
|
||||
@ -364,7 +372,12 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
clear_screen();
|
||||
|
||||
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
|
||||
let failed_exercise_hint = match verify(exercises.iter(), (0, exercises.len()), verbose) {
|
||||
let failed_exercise_hint = match verify(
|
||||
exercises.iter(),
|
||||
(0, exercises.len()),
|
||||
verbose,
|
||||
success_hints,
|
||||
) {
|
||||
Ok(_) => return Ok(WatchStatus::Finished),
|
||||
Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))),
|
||||
};
|
||||
@ -386,7 +399,12 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
);
|
||||
let num_done = exercises.iter().filter(|e| e.looks_done()).count();
|
||||
clear_screen();
|
||||
match verify(pending_exercises, (num_done, exercises.len()), verbose) {
|
||||
match verify(
|
||||
pending_exercises,
|
||||
(num_done, exercises.len()),
|
||||
verbose,
|
||||
success_hints,
|
||||
) {
|
||||
Ok(_) => return Ok(WatchStatus::Finished),
|
||||
Err(exercise) => {
|
||||
let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
|
||||
|
||||
@ -2,6 +2,7 @@ use glob::glob;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
/// Contains the structure of resulting rust-project.json file
|
||||
@ -38,11 +39,11 @@ impl RustAnalyzerProject {
|
||||
}
|
||||
|
||||
/// If path contains .rs extension, add a crate to `rust-project.json`
|
||||
fn path_to_json(&mut self, path: String) {
|
||||
if let Some((_, ext)) = path.split_once('.') {
|
||||
fn path_to_json(&mut self, path: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||
if let Some(ext) = path.extension() {
|
||||
if ext == "rs" {
|
||||
self.crates.push(Crate {
|
||||
root_module: path,
|
||||
root_module: path.display().to_string(),
|
||||
edition: "2021".to_string(),
|
||||
deps: Vec::new(),
|
||||
// This allows rust_analyzer to work inside #[test] blocks
|
||||
@ -50,15 +51,16 @@ impl RustAnalyzerProject {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Parse the exercises folder for .rs files, any matches will create
|
||||
/// a new `crate` in rust-project.json which allows rust-analyzer to
|
||||
/// treat it like a normal binary
|
||||
pub fn exercises_to_json(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
for e in glob("./exercises/**/*")? {
|
||||
let path = e?.to_string_lossy().to_string();
|
||||
self.path_to_json(path);
|
||||
for path in glob("./exercises/**/*")? {
|
||||
self.path_to_json(path?)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ pub fn verify<'a>(
|
||||
exercises: impl IntoIterator<Item = &'a Exercise>,
|
||||
progress: (usize, usize),
|
||||
verbose: bool,
|
||||
success_hints: bool,
|
||||
) -> Result<(), &'a Exercise> {
|
||||
let (num_done, total) = progress;
|
||||
let bar = ProgressBar::new(total as u64);
|
||||
@ -25,9 +26,9 @@ pub fn verify<'a>(
|
||||
|
||||
for exercise in exercises {
|
||||
let compile_result = match exercise.mode {
|
||||
Mode::Test => compile_and_test(exercise, RunMode::Interactive, verbose),
|
||||
Mode::Compile => compile_and_run_interactively(exercise),
|
||||
Mode::Clippy => compile_only(exercise),
|
||||
Mode::Test => compile_and_test(exercise, RunMode::Interactive, verbose, success_hints),
|
||||
Mode::Compile => compile_and_run_interactively(exercise, success_hints),
|
||||
Mode::Clippy => compile_only(exercise, success_hints),
|
||||
};
|
||||
if !compile_result.unwrap_or(false) {
|
||||
return Err(exercise);
|
||||
@ -46,12 +47,12 @@ enum RunMode {
|
||||
|
||||
// Compile and run the resulting test harness of the given Exercise
|
||||
pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
|
||||
compile_and_test(exercise, RunMode::NonInteractive, verbose)?;
|
||||
compile_and_test(exercise, RunMode::NonInteractive, verbose, false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Invoke the rust compiler without running the resulting binary
|
||||
fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
|
||||
fn compile_only(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Compiling {exercise}..."));
|
||||
progress_bar.enable_steady_tick(100);
|
||||
@ -59,11 +60,11 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
|
||||
let _ = compile(exercise, &progress_bar)?;
|
||||
progress_bar.finish_and_clear();
|
||||
|
||||
Ok(prompt_for_completion(exercise, None))
|
||||
Ok(prompt_for_completion(exercise, None, success_hints))
|
||||
}
|
||||
|
||||
// Compile the given Exercise and run the resulting binary in an interactive mode
|
||||
fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
|
||||
fn compile_and_run_interactively(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Compiling {exercise}..."));
|
||||
progress_bar.enable_steady_tick(100);
|
||||
@ -84,12 +85,12 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(prompt_for_completion(exercise, Some(output.stdout)))
|
||||
Ok(prompt_for_completion(exercise, Some(output.stdout), success_hints))
|
||||
}
|
||||
|
||||
// Compile the given Exercise as a test harness and display
|
||||
// the output if verbose is set to true
|
||||
fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Result<bool, ()> {
|
||||
fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool, success_hints: bool) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Testing {exercise}..."));
|
||||
progress_bar.enable_steady_tick(100);
|
||||
@ -104,7 +105,7 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Re
|
||||
println!("{}", output.stdout);
|
||||
}
|
||||
if let RunMode::Interactive = run_mode {
|
||||
Ok(prompt_for_completion(exercise, None))
|
||||
Ok(prompt_for_completion(exercise, None, success_hints))
|
||||
} else {
|
||||
Ok(true)
|
||||
}
|
||||
@ -142,12 +143,11 @@ fn compile<'a, 'b>(
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) -> bool {
|
||||
fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>, success_hints: bool) -> bool {
|
||||
let context = match exercise.state() {
|
||||
State::Done => return true,
|
||||
State::Pending(context) => context,
|
||||
};
|
||||
|
||||
match exercise.mode {
|
||||
Mode::Compile => success!("Successfully ran {}!", exercise),
|
||||
Mode::Test => success!("Successfully tested {}!", exercise),
|
||||
@ -167,7 +167,6 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
|
||||
Mode::Test => "The code is compiling, and the tests pass!",
|
||||
Mode::Clippy => clippy_success_msg,
|
||||
};
|
||||
|
||||
println!();
|
||||
if no_emoji {
|
||||
println!("~*~ {success_msg} ~*~")
|
||||
@ -183,6 +182,13 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
|
||||
println!("{}", separator());
|
||||
println!();
|
||||
}
|
||||
if success_hints {
|
||||
println!("Hints:");
|
||||
println!("{}", separator());
|
||||
println!("{}", exercise.hint);
|
||||
println!("{}", separator());
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("You can keep working on this exercise,");
|
||||
println!(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user