rustlings/exercises/15_traits/traits2.rs

23 lines
490 B
Rust
Raw Normal View History

2020-02-25 09:48:50 +00:00
trait AppendBar {
fn append_bar(self) -> Self;
}
2024-06-27 10:58:44 +01:00
// TODO: Implement the trait `AppendBar` for a vector of strings.
// `appned_bar` should push the string "Bar" into the vector.
2020-02-25 09:48:50 +00:00
fn main() {
// You can optionally experiment here.
}
2020-02-25 09:48:50 +00: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 10:58:44 +01:00
assert_eq!(foo.pop().unwrap(), "Bar");
assert_eq!(foo.pop().unwrap(), "Foo");
2020-02-25 09:48:50 +00:00
}
2020-02-25 11:00:09 +00:00
}