Johanna Larsson
Johanna Larsson

Reputation: 10761

Comparing string with static string

Here's an example of what I've tried.

static TARGET: &'static str = "a string";

fn main () {
  printfln!("%?", TARGET.eq(~"other string"));
}

I looked at equiv too, but no luck. The string I compare to the TARGET has to be an owned pointer string.

Upvotes: 3

Views: 5666

Answers (1)

Ercan Erden
Ercan Erden

Reputation: 1926

This works here:

static TARGET: &'static str = "a string";

fn main () {

  println!("{}", TARGET == "a string");
  println!("{}", TARGET == ~"a string");

  let other = ~"a string";
  println!("{}", TARGET == other);

}

It prints:

true
true
true

Upvotes: 4

Related Questions