Решение на упр.06 задача 1 от Борис Ханджиев
Резултати
- 4 точки от тестове
- 0 бонус точки
- 4 точки общо
- 4 успешни тест(а)
- 0 неуспешни тест(а)
Код
pub struct ImportantExcerpt<'a> {
pub part: &'a str,
}
impl<'a> ImportantExcerpt<'a> {
pub fn level(&self) -> i32 {
3
}
pub fn announce_and_return_part(&self, announcement: &str) -> &str {
println!("{announcement}");
self.part
}
}
pub fn first_or_default<'a>(text1: &'a str, text2: &'a str, threshold: usize) -> &'a str {
if text1.len() >= threshold {
text1
} else {
text2
}
}
pub fn first_word<'a>(s: &'a str) -> &'a str {
s.split_whitespace().next().unwrap_or(s)
}
pub fn find_longest_excerpt<'a>(excerpts: &'a [ImportantExcerpt]) -> Option<&'a str> {
excerpts
.iter()
.map(|excerpt| excerpt.part)
.max_by_key(|&part| part.len())
}
fn main()
{
}
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20261119-2321049-1uzehfs/solution)
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.38s
Running unittests src/lib.rs (target/debug/deps/solution-2e550d2f70dd933d)
running 4 tests
test solution_test::test_find_longest ... ok
test solution_test::test_find_longest_2 ... ok
test solution_test::test_first_or_default ... ok
test solution_test::test_first_word ... ok
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
