Skip to content
On this page

介绍1:exercises/intro/intro1.rs

第一个题目其实不算题目,只是一个rustlings的使用介绍,不存在任何编译错误,所以这里讲怎么开始练习。

rust
fn main() {
    println!("Hello and");
    println!(r#"       welcome to...                      "#);
    println!(r#"                 _   _ _                  "#);
    println!(r#"  _ __ _   _ ___| |_| (_)_ __   __ _ ___  "#);
    println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#);
    println!(r#" | |  | |_| \__ \ |_| | | | | | (_| \__ \ "#);
    println!(r#" |_|   \__,_|___/\__|_|_|_| |_|\__, |___/ "#);
    println!(r#"                               |___/      "#);
    println!();
    println!("This exercise compiles successfully. The remaining exercises contain a compiler");
    println!("or logic error. The central concept behind Rustlings is to fix these errors and");
    println!("solve the exercises. Good luck!");
    println!();
    println!("The source for this exercise is in `exercises/intro/intro1.rs`. Have a look!");
    println!(
        "Going forward, the source of the exercises will always be in the success/failure output."
    );
    println!();
    println!(
        "If you want to use rust-analyzer, Rust's LSP implementation, make sure your editor is set"
    );
    println!("up, and then run `rustlings lsp` before continuing.")
}

开始练习

  • 我们使用vscode或者其他编辑器打开项目
  • 在编辑器的terminal中运行命令rustlings watch,我们可以看到一个介绍页面如下:

rustlings-watch

大致的意思是说:本练习(介绍页面)编译成功,剩下练习会包含一些编译错误或者逻辑错误,你需要做的就是修复这些错误,并让其顺利编译运行通过。

提示

如果当次练习已经完成(编译运行通过),你可以删除文件中的I AM NOT DONE这一行注释,就会进入下一个题目。

从命令输出我们还能看到关键信息就是Process进度下方练习的文件名,以便我们能快速找到练习文件所在位置。

知识点

虽然这只是一个介绍页,但是我们也应该关注这里面的知识点:

  • println!宏的使用

参考资料

进入下一关

我们将代码注释中的I AM NOT DONE去掉,就会进入下一关。

Powered by VitePress