Merge branch 'new' of https://github.com/rustlings/rustlings into new
This commit is contained in:
commit
ab5472baa3
|
@ -7,3 +7,4 @@ authors = ["olivia <olivia@fastmail.com>"]
|
|||
clap = "2.32.0"
|
||||
indicatif = "0.9.0"
|
||||
console = "0.6.2"
|
||||
syntect = "3.0.2"
|
||||
|
|
4
default_out.md
Normal file
4
default_out.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
## Welcome to Rustlings!
|
||||
|
||||
To get started, run `rustlings verify` in order to get the first exercise.
|
||||
Make sure to have your editor open!
|
47
ex6.rs
Normal file
47
ex6.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
// ex6.rs
|
||||
// Make me compile! Scroll down for hints :)
|
||||
|
||||
fn main() {
|
||||
let robot_name = Some(String::from("Bors"));
|
||||
|
||||
match robot_name {
|
||||
Some(name) => println!("Found a name: {}", name),
|
||||
None => (),
|
||||
}
|
||||
|
||||
println!("robot_name is: {:?}", robot_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Hint: The following two statements are equivalent:
|
||||
// let x = &y;
|
||||
// let ref x = y;
|
24
src/main.rs
24
src/main.rs
|
@ -2,15 +2,21 @@
|
|||
extern crate clap;
|
||||
extern crate console;
|
||||
extern crate indicatif;
|
||||
extern crate syntect;
|
||||
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use console::{style, Emoji};
|
||||
use indicatif::ProgressBar;
|
||||
use syntect::easy::HighlightFile;
|
||||
use syntect::parsing::SyntaxSet;
|
||||
use syntect::highlighting::{ThemeSet, Style};
|
||||
use syntect::util::{as_24_bit_terminal_escaped, LinesWithEndings};
|
||||
use std::fs::remove_file;
|
||||
use std::io::BufRead;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let matches = App::new("r2")
|
||||
let matches = App::new("rustlings")
|
||||
.version(crate_version!())
|
||||
.author("Olivia Hugger")
|
||||
.about("Test")
|
||||
|
@ -21,6 +27,9 @@ fn main() {
|
|||
.arg(Arg::with_name("file").required(true).index(1)),
|
||||
).get_matches();
|
||||
|
||||
let ss = SyntaxSet::load_defaults_newlines();
|
||||
let ts = ThemeSet::load_defaults();
|
||||
|
||||
println!(r#" _ _ _ "#);
|
||||
println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#);
|
||||
println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#);
|
||||
|
@ -130,6 +139,17 @@ fn main() {
|
|||
compile_only("exercises/error_handling/option1.rs");
|
||||
test("exercises/error_handling/result1.rs");
|
||||
}
|
||||
|
||||
if let None = matches.subcommand_name() {
|
||||
let mut highlighter = HighlightFile::new("default_out.md", &ss, &ts.themes["base16-eighties.dark"]).unwrap();
|
||||
for maybe_line in highlighter.reader.lines() {
|
||||
let line = maybe_line.unwrap();
|
||||
let regions: Vec<(Style, &str)> = highlighter.highlight_lines.highlight(&line, &ss);
|
||||
println!("{}", as_24_bit_terminal_escaped(®ions[..], true));
|
||||
}
|
||||
}
|
||||
|
||||
println!("\x1b[0m");
|
||||
}
|
||||
|
||||
fn compile_only(filename: &str) {
|
||||
|
@ -137,7 +157,7 @@ fn compile_only(filename: &str) {
|
|||
bar.set_message(format!("Compiling {}...", filename).as_str());
|
||||
bar.enable_steady_tick(100);
|
||||
let compilecmd = Command::new("rustc")
|
||||
.args(&[filename, "-o", "temp"])
|
||||
.args(&[filename, "-o", "temp", "--color", "always"])
|
||||
.output()
|
||||
.expect("fail");
|
||||
bar.finish_and_clear();
|
||||
|
|
Loading…
Reference in a new issue