Rustacious way of checking if string ends with any suffix from a selection What's the best way to check if a String ends with any of multiple suffixes in Rust?

I have a working, naive solution:

fn string_ends_with_any(s: String, suffixes: Vec&lt;&amp;str&gt;) -&gt; bool {
    for suffix in &amp;suffixes {
        if s.ends_with(suffix) {
            return true;
        }
    }
    false
}


Note: suffixes could have varying lengths

As I am quite new to Rust, I would very much appreciate any/all suggestions about how my code can better leverage Rust idioms.

Here are some test cases I need to function pass

#[test]
fn empty_suffixes() {
    let s = String::from("5m");
    let suffixes = vec![];

    assert!(!string_ends_with_any(s, suffixes))
}

#[test]
fn empty_string_has_no_suffix() {
    let s = String::from("");
    let suffixes = vec!["txt"];

    assert!(!string_ends_with_any(s, suffixes))
}

#[test]
fn string_ends_with_first_suffix() {
    let s = String::from("foo.txt");
    let suffixes = vec!["txt", "csv"];

    assert!(string_ends_with_any(s, suffixes))
}

#[test]
fn string_ends_with_last_suffix() {
    let s = String::from("foo.csv");
    let suffixes = vec!["txt", "csv"];

    assert!(string_ends_with_any(s, suffixes))
}

#[test]
fn string_doesnt_end_with_any_suffix() {
    let s = String::from("foo.csv");
    let suffixes = vec!["txt", "tsv"];

    assert!(!string_ends_with_any(s, suffixes))
}

#[test]
fn string_ends_in_suffix_but_case_is_wrong() {
    let s = String::from("foo.csv");
    let suffixes = vec!["txt", "Csv"];

    assert!(!string_ends_with_any(s, suffixes))
}
You could use Iterator:any to write this in a succinct way:

fn string_ends_with_any(s: String, suffixes: Vec&lt;&amp;str&gt;) -&gt; bool {
    return suffixes.iter().any(|&amp;suffix| s.ends_with(suffix));
}


Because this pattern returns true on first match of the predicate:


for suffix in &amp;suffixes {
    if s.ends_with(suffix) {
        return true;
    }
}
false



Whether this is rustacious remains to be seen. I'm by no means an expert in Rust.