Merge pull request #245 from mg-chao/20220119_translate_generics

[rust-exercise] 翻译 generics 部分
pull/247/head
Sunface 3 years ago committed by GitHub
commit e410ffc55c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,7 @@
// This shopping list program isn't compiling!
// Use your knowledge of generics to fix it.
// 这个购物清单程序无法编译!
// 用你对泛型的了解来解决这个问题。
// Execute `rustlings hint generics1` for hints!
// 执行 `rustlings hint generics1` 获取提示!
// I AM NOT DONE

@ -1,7 +1,7 @@
// This powerful wrapper provides the ability to store a positive integer value.
// Rewrite it using generics so that it supports wrapping ANY type.
// 这个强大的 Wrapper 拥有存储一个正整数值的能力。
// 利用泛型重写它使它支持包装wrapping任何类型的值。
// Execute `rustlings hint generics2` for hints!
// 执行 `rustlings hint generics2` 获取提示!
// I AM NOT DONE

@ -1,14 +1,11 @@
// An imaginary magical school has a new report card generation system written in Rust!
// Currently the system only supports creating report cards where the student's grade
// is represented numerically (e.g. 1.0 -> 5.5).
// However, the school also issues alphabetical grades (A+ -> F-) and needs
// to be able to print both types of report card!
// 一所想象的魔法学院有一个采用 Rust 编写的新版成绩单生成系统!
// 目前该系统仅支持创建以数字表示的成绩单(如 1.0 -> 5.5)。
// 然而学校也发布用字母表示的成绩A+ -> F-),所以需要能够打印两种成绩单。
// Make the necessary code changes in the struct ReportCard and the impl block
// to support alphabetical report cards. Change the Grade in the second test to "A+"
// to show that your changes allow alphabetical grades.
// 在 ReportCard 结构定义和 impl 块中进行必要的代码修改,以支持用字母表示的成绩单。
// 将第二个测试的 grade 改为 "A+",用来表明代码已允许按字母表示成绩。
// Execute 'rustlings hint generics3' for hints!
// 执行 'rustlings hint generics3' 获取提示!
// I AM NOT DONE
@ -20,7 +17,7 @@ pub struct ReportCard {
impl ReportCard {
pub fn print(&self) -> String {
format!("{} ({}) - achieved a grade of {}",
format!("{} ({}) - achieved a grade of {}",// 译:{} ({}) - 成绩为 {}"
&self.student_name, &self.student_age, &self.grade)
}
}
@ -44,7 +41,7 @@ mod tests {
#[test]
fn generate_alphabetic_report_card() {
// TODO: Make sure to change the grade here after you finish the exercise.
// TODO:完成练习后,在这里更改 grade 的值。
let report_card = ReportCard {
grade: 2.1,
student_name: "Gary Plotter".to_string(),

@ -516,18 +516,18 @@ name = "generics1"
path = "exercises/generics/generics1.rs"
mode = "compile"
hint = """
Vectors in rust make use of generics to create dynamically sized arrays of any type.
You need to tell the compiler what type we are pushing onto this vector."""
Rust Vector
"""
[[exercises]]
name = "generics2"
path = "exercises/generics/generics2.rs"
mode = "test"
hint = """
Currently we are wrapping only values of type 'u32'.
Maybe we could update the explicit references to this data type somehow?
'u32'
If you are still stuck https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-method-definitions
https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-method-definitions
"""
[[exercises]]
@ -535,12 +535,11 @@ name = "generics3"
path = "exercises/generics/generics3.rs"
mode = "test"
hint = """
To find the best solution to this challenge you're going to need to think back to your
knowledge of traits, specifically Trait Bound Syntax - you may also need this: "use std::fmt::Display;"
trait trait
"use std::fmt::Display;"
This is definitely harder than the last two exercises! You need to think about not only making the
ReportCard struct generic, but also the correct property - you will need to change the implementation
of the struct slightly too...you can do it!
使 ReportCard
💪
"""
# OPTIONS

Loading…
Cancel
Save