DEV Community

Cover image for Structs in Rust

Structs in Rust

Francesco Ciulla on March 12, 2024

In this lesson, we will talk about Structs in Rust What are Structs? Structs are a way to create more complex data types. They are si...
Collapse
 
nigel447 profile image
nigel447

prefer this syntax to golang, content here is very useful, its a shame that the code blocks are not formatted for clarity

struct MyStruct {
name:String,
}

Collapse
 
francescoxx profile image
Francesco Ciulla

it should be fixed now, thanks

Collapse
 
sdrsdr profile image
Stoian Ivanov

Instances from other instances example is not really good! User.email is moved to new_user and if you try to use it the compiler gets engry 😃

Collapse
 
francescoxx profile image
Francesco Ciulla

There are different ways to avoid this (I explain it in the video but I didn't want to make the article too long). you can either clone() the single propery or even clone the whole instance adding the clone trait to the struct