Home

基本执行环境(working)

应用程序与基本执行环境(working) 本章最主要的目的是让应用和硬件分离,对访问硬件进行比较初级的抽象。 今天或许短暂,但过去即是永恒。 准备工作 环境 Ubuntu18.04+vscode+docker+qemu5.0.0 toolchain: rustc 1.55.0-nightly qemu能够模拟一个完整的基于不同CPU的硬件系统,包括处理器、内存及其他外部设备,支持运行完整的操作系统。 这一节使用的都是qemu的User Mode模式,用户态模拟,不是完全的裸机。 老规矩,从”hello,world“开始。 当我们满怀着好奇心在编辑器内键入仅仅数个字节,再经过几行命令编译(编译器)、运行(操作系统),终于在黑洞洞的终端窗...

Read more

rustlings-macros

macros1 // macros1.rs // Make me compile! Execute `rustlings hint macros1` for hints :) macro_rules! my_macro { () => { println!("Check out my macro!"); }; } fn main() { my_macro(); } 这个题目的问题是调用宏的时候没加!,现在这样是相当于调用名为my_macro()的函数。只要加个!就能解决。 但是我们也详细说说macro_rules!,这个将来会被淘汰的宏类型。 我们已经用过很多种宏了。但是还没完全探索什么是宏以及它是如何工作的。 宏(Mac...

Read more

rustlings-thread

thread1 // threads1.rs // Make this compile! Execute `rustlings hint threads1` for hints :) // The idea is the thread spawned on line 22 is completing jobs while the main thread is // monitoring progress until 10 jobs are completed. Because of the difference between the // spawned threads' sleep time, and the waiting threads sleep time, when you...

Read more

rustlings-迭代器和闭包

iterators1 // iterators1.rs // // Make me compile by filling in the `???`s // // When performing operations on elements within a collection, iterators are essential. // This module helps you get familiar with the structure of using an iterator and // how to go through elements within an iterable collection. // // Execute `rustlings hint iterato...

Read more

rustlings-智能指针

box1 // box1.rs // // At compile time, Rust needs to know how much space a type takes up. This becomes problematic // for recursive types, where a value can have as part of itself another value of the same type. // To get around the issue, we can use a `Box` - a smart pointer used to store data on the heap, // which also allows us to wrap a recu...

Read more

rustlings-test

test1 // tests1.rs // Tests are important to ensure that your code does what you think it should do. // Tests can be run on this file with the following command: // rustlings run tests1 // This test has a problem with it -- make the test compile! Make the test // pass! Make the test fail! Execute `rustlings hint tests1` for hints :) // I AM NO...

Read more

rustlings-traits

traits1 // traits1.rs // Time to implement some traits! // // Your task is to implement the trait // `AppendBar' for the type `String'. // // The trait AppendBar has only one function, // which appends "Bar" to any object // implementing this trait. // I AM NOT DONE trait AppendBar { fn append_bar(self) -> Self; } impl AppendBar for St...

Read more

rustlings-option

option1 // option1.rs // Make me compile! Execute `rustlings hint option1` for hints // you can modify anything EXCEPT for this function's sig fn print_number(maybe_number: Option<u16>) { println!("printing: {}", maybe_number.unwrap()); } fn main() { print_number(13); print_number(99); let mut numbers: [Option<u16>...

Read more