Structs in Rust
# Structs
in other languages there are classes, in Rust there are Structs
structs can have
- data fields
- methods
- associated functions
structs should be in capital cammelcase
|
|
you can end last field with a comma too.
Instantiating a struct is straight forward but verbose. you need to call it and set a value for each field.
to make this easier you can use a constructor, these are defined in an implementation
|
|
fn new => is an associate function. Because it doesn’t have a form of self as first parameter. In other languages you might call this a class method. with new being the conventional name used to instantiate.
|
|
here the scope operators :: are used to access the method inside the struct.
no struct inheritance. = fixes OOP stuff