Search code examples
rustrust-obsolete

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.


Solution

  • 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