Exercise 05 / 24: The secret alarm

// Iterators of Code 2026 — Day 05: The secret alarm
// Refactor contains_secret using iterators. This deliberately simple check
// flags a path whose final component is exactly ".env" or "id_rsa".
// Stop inspecting paths as soon as a match is found; do not build a list.

fn contains_secret(paths: &[&str]) -> bool {
    let mut found = false;
    for path in paths {
        let filename = path.rsplit('/').next().unwrap_or("");
        if filename == ".env" || filename == "id_rsa" {
            found = true;
            break;
        }
    }
    found
}

fn main() {
    assert!(contains_secret(&[
        "src/main.rs",
        "config/.env",
        "README.md"
    ]));
    assert!(contains_secret(&["id_rsa"]));
    assert!(!contains_secret(&[".env.example", "docs/id_rsa.md"]));
    assert!(!contains_secret(&[]));
}

Your solution

Standalone .rs / std only. Stored, not executed.

60 characters max. Not a login.

File overrides pasted code.

Maximum solution size: 64 KiB.

Editing access uses this browser's cookie. Clearing cookies loses access.