Решение на упр.06 задача 1 от Иван Игнатов

Обратно към всички решения

Към профила на Иван Игнатов

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 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 {
match s.find(' ') {
Some(idx) => &s[..idx],
None => s,
}
}
pub fn find_longest_excerpt<'a>(excerpts: &'a [ImportantExcerpt]) -> Option<&'a str> {
let mut longest_excerpt: Option<&'a str> = None;
for excerpt in excerpts {
match longest {
Some(current) if current.len() >= excerpt.part.len() => {}
_ => longest_excerpt = Some(excerpt.part),
}
}
longest
}

Лог от изпълнението

Compiling solution v0.1.0 (/tmp/d20261119-2321049-38i4e7/solution)
error[E0425]: cannot find value `longest` in this scope
  --> src/lib.rs:34:15
   |
34 |         match longest {
   |               ^^^^^^^ not found in this scope

error[E0425]: cannot find value `longest` in this scope
  --> src/lib.rs:39:5
   |
39 |     longest
   |     ^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0425`.
error: could not compile `solution` (lib test) due to 2 previous errors

История (1 версия и 2 коментара)

Иван качи първо решение на 18.11.2026 23:55 (преди 12 дена)

Имаш компилационна грешка:

Compiling solution v0.1.0 (/tmp/d20261119-2321049-38i4e7/solution)
error[E0425]: cannot find value `longest` in this scope
  --> src/lib.rs:34:15
   |
34 |         match longest {
   |               ^^^^^^^ not found in this scope

error[E0425]: cannot find value `longest` in this scope
  --> src/lib.rs:39:5
   |
39 |     longest
   |     ^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0425`.
error: could not compile `solution` (lib test) due to 2 previous errors