On Sun, Apr 28, 2013 at 10:45 AM, Patrick Walton <[email protected]>wrote:

> If you need to compare a `~str` against a constant string, use .equiv():
>

I have some code where I'm trying to match an owned string against a set of
constant strings, and it's not clear to me how to take your advice there.

fn match_upper(to_match: &str) -> int {
    match to_match.to_ascii().to_upper().to_str_ascii() {
        ~"ABC" => 1, ~"DEF" => 2, ~"GHI" => 3, _ => 0
    }
}

Does each call to this function heap-allocate all the owned strings in the
match expression?  If so, how could I avoid that?  Is there a more
idiomatic way to do what I'm trying to do?

Thanks for the PSA,
Mitch
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to