Rost Tupel gegen Vec
//When to use array, vecotr, tuple, struct, enum, union:
Array
A continuous array of elements of immutable size. Defined as [type; size] like: [string; 3]
Vector
Basically an array, but with mutable size.
Example: let names = Vec::new() creates a new vector, then we can push items into it: names.push("retu")
Tuple
Basically a struct with unnamed members: a tuple contains any n number of elements, but doesn’t care about their types, but is not of mutable size.
Example: let user_data = ("retu", 1029384, User::new())
Tuples are usually used to return multiple items from a function and you access their members using a number similar to an array’s index: user_data.0, user_data.1 etc.
Struct
The basic data structure in rust. Defined like so:
struct MyStruct{/*my members*/}
struct MyStruct(/*member types*/);
struct MyStruct; //empty structure
Structures are a bit too complicated to talk about in just one post, so please take a look at the rust book.
Enum
A type of variable that can be any of the types declared within the enum. These again, are pretty complicated if we’re talking about rust enums, so please refer to the rust book.
Union
A type of variable that contains only one of the objects defined within it, and is the size of the largest object that it can contain. Probably not something you’ll use too often. Unless you’re interfacing with low-level libraries in C or C++
Flyhouse_Squarewheel