From c40b3fc7aa11b125d97451a3015b02f77517c531 Mon Sep 17 00:00:00 2001 From: TimLai666 <43640816+TimLai666@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:05:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BF=BB=E8=AD=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/14_generics/README.md | 13 +++++-------- exercises/14_generics/generics1.rs | 6 ++---- exercises/14_generics/generics2.rs | 7 +++---- exercises/15_traits/README.md | 22 +++++++++++----------- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/exercises/14_generics/README.md b/exercises/14_generics/README.md index de46d503..4756b96f 100644 --- a/exercises/14_generics/README.md +++ b/exercises/14_generics/README.md @@ -1,11 +1,8 @@ -# Generics +# 泛型 -Generics is the topic of generalizing types and functionalities to broader cases. -This is extremely useful for reducing code duplication in many ways, but can call for rather involving syntax. -Namely, being generic requires taking great care to specify over which types a generic type is actually considered valid. -The simplest and most common use of generics is for type parameters. +泛型是一個將類型和功能擴展到更廣泛情況的主題。這在許多方面對減少代碼重複非常有用,但也可能需要相當複雜的語法。具體來說,泛型需要非常謹慎地指定泛型類型實際上在哪些類型上是有效的。最簡單和最常見的泛型使用方式是類型參數。 -## Further information +## 進一步了解 -- [Generic Data Types](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html) -- [Bounds](https://doc.rust-lang.org/rust-by-example/generics/bounds.html) +- [泛型資料類型](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html) +- [邊界](https://doc.rust-lang.org/rust-by-example/generics/bounds.html) diff --git a/exercises/14_generics/generics1.rs b/exercises/14_generics/generics1.rs index 35c1d2fe..57d0bc75 100644 --- a/exercises/14_generics/generics1.rs +++ b/exercises/14_generics/generics1.rs @@ -1,10 +1,8 @@ // generics1.rs // -// This shopping list program isn't compiling! Use your knowledge of generics to -// fix it. +// 這個購物清單程式無法編譯!用您對泛型的了解來修復它。 // -// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a -// hint. +// 執行 `rustlings hint generics1` 或使用 `hint` watch 子命令來獲取提示。 // I AM NOT DONE diff --git a/exercises/14_generics/generics2.rs b/exercises/14_generics/generics2.rs index 074cd938..8dd36cad 100644 --- a/exercises/14_generics/generics2.rs +++ b/exercises/14_generics/generics2.rs @@ -1,10 +1,9 @@ // generics2.rs // -// This powerful wrapper provides the ability to store a positive integer value. -// Rewrite it using generics so that it supports wrapping ANY type. +// 這個強大的包裝器提供了存儲正整數值的能力。 +// 使用泛型重寫它,使其支援包裝任何類型。 // -// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a -// hint. +// 執行 `rustlings hint generics2` 或使用 `hint` watch 子命令來獲取提示。 // I AM NOT DONE diff --git a/exercises/15_traits/README.md b/exercises/15_traits/README.md index ac87c64e..2ee46180 100644 --- a/exercises/15_traits/README.md +++ b/exercises/15_traits/README.md @@ -1,19 +1,19 @@ -# Traits +# 特徵 (Traits) -A trait is a collection of methods. +特徵是一組方法的集合。 -Data types can implement traits. To do so, the methods making up the trait are defined for the data type. For example, the `String` data type implements the `From<&str>` trait. This allows a user to write `String::from("hello")`. +資料類型可以實現特徵。為此,需要為資料類型定義構成特徵的方法。例如,`String` 資料類型實現了 `From<&str>` 特徵。這使得用戶可以編寫 `String::from("hello")`。 -In this way, traits are somewhat similar to Java interfaces and C++ abstract classes. +這樣,特徵在某種程度上類似於 Java 的接口(interfaces)和 C++ 的抽象類(abstract classes)。 -Some additional common Rust traits include: +一些其他常見的 Rust 特徵包括: -- `Clone` (the `clone` method) -- `Display` (which allows formatted display via `{}`) -- `Debug` (which allows formatted display via `{:?}`) +- `Clone`(`clone` 方法) +- `Display`(允許透過 `{}` 進行格式化顯示) +- `Debug`(允許透過 `{:?}` 進行格式化顯示) -Because traits indicate shared behavior between data types, they are useful when writing generics. +由於特徵定義了資料類型之間的共享行為,它們在編寫泛型時非常有用。 -## Further information +## 進一步了解 -- [Traits](https://doc.rust-lang.org/book/ch10-02-traits.html) +- [特徵](https://doc.rust-lang.org/book/ch10-02-traits.html)