User Tools

Site Tools


devlogs:8_5_2022

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devlogs:8_5_2022 [2022/05/09 23:00]
root
devlogs:8_5_2022 [2023/10/19 15:25] (current)
Line 131: Line 131:
 } }
 </code> </code>
 +
 +== Wow tuples! ==
 +Tuples are kinda like arrays but they can hold different types of data.
 +
 +<code rust>
 +let i = (2.0,"alex",false); // () are how you initialize tuples.
 +</code>
 +
 +but like whadoo?? how do you use it?
 +
 +<code rust>
 +fn main() {
 +let i = (2,"alex",false);
 +let (num,name,truth) = i; // Deconstruct it using let
 +let anotherNum = i.0; //Lol yeah you can access it like that too
 +let anotherString = String::from(i.1);
 +match i {
 + (2,"alex",false) => println!("WOW what a specific toople"),
 + //IF first is 0 and then Destructure the second and third elements
 + (0, y, z) => println!("First is `0`, `y` is {:?}, and `z` is {:?}", y, z),
 + (1, ..)  => println!("First is `1` and the rest doesn't matter"),
 + //`..` can be used to ignore the rest of the tuple
 +      => println!("It doesn't matter what they are"),
 + // `_` means don't bind the value to a variable
 +    }
 +}
 +
 +</code>
 +that is all.
  
 ~~DISCUSSION | Gosy ~~ ~~DISCUSSION | Gosy ~~
devlogs/8_5_2022.1652155219.txt.gz ยท Last modified: 2023/10/13 16:43 (external edit)