News for hackers. Stuff that matters.
Re:First Impressions of the Rust Programming Language by earenndil on Sunday June 10, 2018 @07:01PM (#17280630)
Is it? It does something with y if it is something, otherwise it does nothing...
Re:First Impressions of the Rust Programming Language by chrismorgan on Monday June 11, 2018 @08:04AM (#17283546)
To make clearer what I meant by pattern bindings being available:

  if let Some(x) = y {
      println!("y has a value, {}", x);
  }
Whereas with a method, the contents of the variant are not bound:

  if y.is_some() {
      println!("y has a value, {}", /* uh… */);
  }
In Rust, pattern matching is the only to get at the contents of an enum. Methods like is_some() are just this:

  pub fn is_some(&self) -> bool {
      match *self {
          Some(_) => true,
          None => false,
      }
  }