rustlings/exercises/15_traits/traits2.rs

23 lines
490 B
Rust
Raw Normal View History

2020-02-25 12:48:50 +03:00
trait AppendBar {
fn append_bar(self) -> Self;
}
2024-06-27 12:58:44 +03:00
// TODO: Implement the trait `AppendBar` for a vector of strings.
2024-07-02 15:28:08 +03:00
// `append_bar` should push the string "Bar" into the vector.
2020-02-25 12:48:50 +03:00
fn main() {
// You can optionally experiment here.
}
2020-02-25 12:48:50 +03:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_vec_pop_eq_bar() {
let mut foo = vec![String::from("Foo")].append_bar();
2024-06-27 12:58:44 +03:00
assert_eq!(foo.pop().unwrap(), "Bar");
assert_eq!(foo.pop().unwrap(), "Foo");
2020-02-25 12:48:50 +03:00
}
2020-02-25 14:00:09 +03:00
}