Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Get Values Out Of A Tuple In Rust

This is how to access the values of a rust tuple directly

Code

fn main() {
      let characters: (char, char, char) = ('a', 'b', 'c');

      println!("The second character is: {}", characters.1)
  }

Results

The second character is: b

*** Destructuring

And this is how to do it with destructuring

Code

fn main() {
      let numbers: (i32, f64, i32) = (500, 6.4, 1);

      let (x, y, z) = numbers;

      println!("The value of y is: {}", y);
  }

Results

The value of y is: 6.4