You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
619 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// traits2.rs
//
// 你的任务是为一个字符串 vector 实现 `AppendBar` trait。
//
// 为了实现该 trait请思考下将 "Bar" 追加到字符串 vector 的意义是什么?
//
// 这次没有样板代码,相信自己!
// I AM NOT DONE
trait AppendBar {
fn append_bar(self) -> Self;
}
//TODO在这编写代码
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_vec_pop_eq_bar() {
let mut foo = vec![String::from("Foo")].append_bar();
assert_eq!(foo.pop().unwrap(), String::from("Bar"));
assert_eq!(foo.pop().unwrap(), String::from("Foo"));
}
}