From 2048a2cfc61c38e7a425cf6d0476b1f7e3853386 Mon Sep 17 00:00:00 2001 From: sunface Date: Tue, 8 Mar 2022 17:15:53 +0800 Subject: [PATCH] add zh/advanced-traits.md --- src/generics-traits/advanced-traits.md | 2 +- zh-CN/src/generics-traits/advanced-traits.md | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/generics-traits/advanced-traits.md b/src/generics-traits/advanced-traits.md index 1fcccbe..7882ce3 100644 --- a/src/generics-traits/advanced-traits.md +++ b/src/generics-traits/advanced-traits.md @@ -17,7 +17,7 @@ Using of `Address` is much more clearable and convenient than `AsRef<[u8]> + Clo struct Container(i32, i32); // USING associated types to re-implement trait Contains. -// trait Container { +// trait Contains { // type A; // type B; diff --git a/zh-CN/src/generics-traits/advanced-traits.md b/zh-CN/src/generics-traits/advanced-traits.md index 1fcccbe..f4775b7 100644 --- a/zh-CN/src/generics-traits/advanced-traits.md +++ b/zh-CN/src/generics-traits/advanced-traits.md @@ -1,7 +1,7 @@ -# Advance Traits +# 进一步深入特征 -## Associated types -The use of "Associated types" improves the overall readability of code by moving inner types locally into a trait as output types. For example : +## 关联类型 +关联类型主要用于提升代码的可读性,例如以下代码 : ```rust pub trait CacheableItem: Clone + Default + fmt::Debug + Decodable + Encodable { type Address: AsRef<[u8]> + Clone + fmt::Debug + Eq + Hash; @@ -9,15 +9,15 @@ pub trait CacheableItem: Clone + Default + fmt::Debug + Decodable + Encodable { } ``` -Using of `Address` is much more clearable and convenient than `AsRef<[u8]> + Clone + fmt::Debug + Eq + Hash`. +相比 `AsRef<[u8]> + Clone + fmt::Debug + Eq + Hash`, `Address` 的使用可以极大的极少其它类型在实现该特征时所需的模版代码. 1. 🌟🌟🌟 ```rust,editable struct Container(i32, i32); -// USING associated types to re-implement trait Contains. -// trait Container { +// 使用关联类型实现重新实现以下特征 +// trait Contains { // type A; // type B;