Search
 
SCRIPT & CODE EXAMPLE
 

RUST

rust tuple vs 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++
Comment

PREVIOUS NEXT
Code Example
Rust :: armanriazi•rust•unsafe•static 
Rust :: rust hashset 
Rust :: rust find type 
Lua :: roblox for children loop 
Lua :: luau make rainbow part 
Lua :: roblox jsonencode 
Lua :: absolute value in lua 
Lua :: roblox send message script 
Lua :: roblox index and newindex 
Lua :: roblox tween color part 
Lua :: Pass values to functions from Onclicks roblox 
Lua :: roblox how to find value in table 
Lua :: roblox buy gamepass script 
Lua :: lua create file 
Lua :: json resume shema 
Lua :: string.match roblox 
Lua :: how to access an index of a table lua 
Lua :: What is The Color changing script for luaa 
Lua :: what is a value lua 
Lua :: lua loop through string 
Lua :: swap number in lua 
Lua :: name is not a valid member of Folder roblox 
Matlab :: matlab rlocus 
Matlab :: matlab variables 
Basic :: cmd cant change directory 
Basic :: wussup 
Elixir :: elixir datetime to timestamp 
Elixir :: elixir "hd" programming 
Scala :: reduce scala 
Actionscript :: docker compose enable rabbitmq enable plugins 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =