mirror of
https://github.com/ArthurDanjou/rustlings.git
synced 2026-02-04 05:37:50 +01:00
- Created empty solution files for various exercises in strings, modules, hashmaps, options, error handling, generics, traits, lifetimes, tests, iterators, smart pointers, threads, macros, clippy, conversions, and quizzes. - Each solution file contains a main function with a comment indicating that it will be automatically filled after completing the exercise. - Added a README.md file to provide information about the solutions and their purpose.
30 lines
653 B
Rust
30 lines
653 B
Rust
trait AppendBar {
|
|
fn append_bar(self) -> Self;
|
|
}
|
|
|
|
// TODO: Implement the trait `AppendBar` for a vector of strings.
|
|
// `append_bar` should push the string "Bar" into the vector.
|
|
impl AppendBar for Vec<String> {
|
|
fn append_bar(self) -> Self {
|
|
let mut result = self;
|
|
result.push(String::from("Bar"));
|
|
result
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
// You can optionally experiment here.
|
|
}
|
|
|
|
#[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(), "Bar");
|
|
assert_eq!(foo.pop().unwrap(), "Foo");
|
|
}
|
|
}
|