Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ModWU/rust-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

Rust Practice

这是一个独立的 Rust 练习工程,路径:

/Users/wikiglobal/projects/rust-practice

怎么练

练习都放在 src/exercises/ 目录下,每个文件对应一个学习步骤和一个主要类别。src/lib.rs 只负责导出模块,不放具体题目。

全部练习可以直接运行:

cargo test

如果只想运行某一道练习,可以按测试名过滤:

cargo test exercise_07
cargo test exercise_08

目录结构

src/
 lib.rs
 main.rs
 exercises.rs
 exercises/
 step_01_ownership_borrowing.rs
 step_02_error_handling.rs
 step_03_collections_iterators.rs
 step_04_structs_methods.rs
 step_05_enums_pattern_matching.rs
 step_06_options_borrowed_lookup.rs
 step_07_traits_generics.rs
 step_08_lifetimes_slices.rs
 step_09_smart_pointers_shared_state.rs
 step_10_concurrency_threads.rs

已完成练习

编号 题目 文件 分类 重点
01 first_word step_01_ownership_borrowing.rs 字符串切片与借用 &strsplit_whitespace、返回借用数据
02 retain_even_numbers step_01_ownership_borrowing.rs 可变借用 &mut Vec<T>、原地修改、retain
03 push_unique step_01_ownership_borrowing.rs 所有权与 String 移动语义、借用比较、避免不必要克隆
04 parse_age step_02_error_handling.rs 错误处理 Result、自定义错误枚举、输入校验
05 word_count step_03_collections_iterators.rs 集合与迭代器 HashMap、文本清洗、计数
06 BankAccount step_04_structs_methods.rs 结构体与方法 structimpl、封装、业务错误

进阶练习

编号 题目 文件 分类 重点
07 advance_ticket step_05_enums_pattern_matching.rs 枚举与模式匹配 enummatch、状态建模
08 find_email step_06_options_borrowed_lookup.rs Option 与借用 集合查找、Option<&str>、返回被借用数据
09 sum_positive_even_squares step_03_collections_iterators.rs 迭代器链式处理 filtermapsum、无中间集合
10 names_starting_with step_07_traits_generics.rs trait 与泛型 trait bound、泛型函数、零拷贝收集
11 longest_trimmed step_08_lifetimes_slices.rs 生命周期 显式生命周期、字符串切片、返回输入之一
12 SharedLog step_09_smart_pointers_shared_state.rs 智能指针 RcRefCell、共享可变状态
13 parallel_sum step_10_concurrency_threads.rs 并发 thread::spawnmove 闭包、join

建议顺序

  1. 先做 01-06,打牢借用、所有权、集合、错误处理和结构体。
  2. 再做 07-11,把 Rust 的类型系统、模式匹配、泛型和生命周期串起来。
  3. 最后做 12-13,理解共享可变状态和线程所有权。

建议先自己写;卡住时再让 AI 解释编译错误,不要直接让 AI 给完整答案。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /