mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-04-03 04:59:19 +00:00
traits2
This commit is contained in:
parent
2ffb454b12
commit
51c535c8ba
@ -17,14 +17,20 @@ trait AppendBar {
|
|||||||
fn append_bar(self) -> Self;
|
fn append_bar(self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Add your code here
|
impl AppendBar for Vec<String> {
|
||||||
|
fn append_bar(self) -> Vec<String> {
|
||||||
|
let mut _vec = self.clone();
|
||||||
|
_vec.push(String::from("Bar"));
|
||||||
|
return _vec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_vec_pop_eq_bar() {
|
fn is_vec_pop_eq_bar() {
|
||||||
let mut foo = vec![String::from("Foo")].append_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("Bar"));
|
||||||
assert_eq!(foo.pop().unwrap(), String::from("Foo"));
|
assert_eq!(foo.pop().unwrap(), String::from("Foo"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user