mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-31 15:59:18 +00:00
翻譯
This commit is contained in:
parent
c40b3fc7aa
commit
798a2f03ae
@ -1,11 +1,9 @@
|
|||||||
// traits1.rs
|
// traits1.rs
|
||||||
//
|
//
|
||||||
// Time to implement some traits! Your task is to implement the trait
|
// 是時候實現一些特徵了!您的任務是為 `String` 類型實現 `AppendBar` 特徵。
|
||||||
// `AppendBar` for the type `String`. The trait AppendBar has only one function,
|
// `AppendBar` 特徵只有一個函數,它將 "Bar" 附加到任何實現了該特徵的對象中。
|
||||||
// which appends "Bar" to any object implementing this trait.
|
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint traits1` or use the `hint` watch subcommand for a
|
// 執行 `rustlings hint traits1` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
// hint.
|
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
@ -14,7 +12,7 @@ trait AppendBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppendBar for String {
|
impl AppendBar for String {
|
||||||
// TODO: Implement `AppendBar` for type `String`.
|
// TODO: 為 `String` 類型實現 `AppendBar`。
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
// traits2.rs
|
// traits2.rs
|
||||||
//
|
//
|
||||||
// Your task is to implement the trait `AppendBar` for a vector of strings. To
|
// 您的任務是為字串向量實現 `AppendBar` 特徵。要實現這個特徵,想一想將 "Bar" 附加到字串向量上意味著什麼。
|
||||||
// implement this trait, consider for a moment what it means to 'append "Bar"'
|
|
||||||
// to a vector of strings.
|
|
||||||
//
|
//
|
||||||
// No boiler plate code this time, you can do this!
|
// 這次沒有模板代碼,您可以做到的!
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint traits2` or use the `hint` watch subcommand for a hint.
|
// 執行 `rustlings hint traits2` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
@ -14,7 +12,7 @@ trait AppendBar {
|
|||||||
fn append_bar(self) -> Self;
|
fn append_bar(self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement trait `AppendBar` for a vector of strings.
|
// TODO: 為字串向量實現 `AppendBar` 特徵。
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
// traits3.rs
|
// traits3.rs
|
||||||
//
|
//
|
||||||
// Your task is to implement the Licensed trait for both structures and have
|
// 您的任務是為兩個結構實現 Licensed 特徵,並讓它們回傳相同的訊息,而不需要兩次編寫相同的函數。
|
||||||
// them return the same information without writing the same function twice.
|
|
||||||
//
|
//
|
||||||
// Consider what you can add to the Licensed trait.
|
// 您考慮一下可以向 Licensed 特徵添加點什麼。
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint traits3` or use the `hint` watch subcommand for a
|
// 執行 `rustlings hint traits3` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
// hint.
|
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
@ -22,8 +20,8 @@ struct OtherSoftware {
|
|||||||
version_number: String,
|
version_number: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Licensed for SomeSoftware {} // Don't edit this line
|
impl Licensed for SomeSoftware {} // 不要編輯這一行
|
||||||
impl Licensed for OtherSoftware {} // Don't edit this line
|
impl Licensed for OtherSoftware {} // 不要編輯這一行
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
// traits4.rs
|
// traits4.rs
|
||||||
//
|
//
|
||||||
// Your task is to replace the '??' sections so the code compiles.
|
// 您的任務是替換 '??' 部分以使代碼通過編譯。
|
||||||
//
|
//
|
||||||
// Don't change any line other than the marked one.
|
// 除了標記的行外,不要更改任何行。
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint traits4` or use the `hint` watch subcommand for a
|
// 執行 `rustlings hint traits4` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
// hint.
|
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ struct OtherSoftware {}
|
|||||||
impl Licensed for SomeSoftware {}
|
impl Licensed for SomeSoftware {}
|
||||||
impl Licensed for OtherSoftware {}
|
impl Licensed for OtherSoftware {}
|
||||||
|
|
||||||
// YOU MAY ONLY CHANGE THE NEXT LINE
|
// 您只能更改下一行
|
||||||
fn compare_license_types(software: ??, software_two: ??) -> bool {
|
fn compare_license_types(software: ??, software_two: ??) -> bool {
|
||||||
software.licensing_info() == software_two.licensing_info()
|
software.licensing_info() == software_two.licensing_info()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
// traits5.rs
|
// traits5.rs
|
||||||
//
|
//
|
||||||
// Your task is to replace the '??' sections so the code compiles.
|
// 您的任務是替換 '??' 部分以使代碼通過編譯。
|
||||||
//
|
//
|
||||||
// Don't change any line other than the marked one.
|
// 除了標記的行外,不要更改任何行。
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint traits5` or use the `hint` watch subcommand for a
|
// 執行 `rustlings hint traits5` 或使用 `hint` watch 子命令來獲取提示。
|
||||||
// hint.
|
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
@ -29,7 +28,7 @@ impl OtherTrait for SomeStruct {}
|
|||||||
impl SomeTrait for OtherStruct {}
|
impl SomeTrait for OtherStruct {}
|
||||||
impl OtherTrait for OtherStruct {}
|
impl OtherTrait for OtherStruct {}
|
||||||
|
|
||||||
// YOU MAY ONLY CHANGE THE NEXT LINE
|
// 您只能更改下一行
|
||||||
fn some_func(item: ??) -> bool {
|
fn some_func(item: ??) -> bool {
|
||||||
item.some_function() && item.other_function()
|
item.some_function() && item.other_function()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user