It's time to learn about structs. In other languages, you have classes in rust, you have structs. structs can have data fields, methods and associated functions. The syntax for the struct and its fields is the keyword struct, then the name of the struct in capital, camel case, Redbox. In this case, then curly braces, and then the fields in there type annotations in a list separated by commas, and does a nice touch, you can end your last field with a comma as well, so the compiler doesn't yell at you when you add another field. And don't think to add a comma to the field before it.
This feature is repeated in lots of rust constructs that use commas. instantiating a struct is straightforward, though verbose, you need to specify a value for every single field. Typically, you would implement an associated function to use as a constructor to create a struct with default values and then call that methods and associated functions that are defined in an implementation. block that is separate from this struct definition. The implementation block starts with imple, and then the name of the struct whose functions and methods you're going to implement. This is an associated function, because it doesn't have a form of self as its first parameter, and many other languages, you would call this a class method.
Associated functions are often used to like constructors and other languages with new being the conventional name to use when you want to create a new struct with default values. You'll note that self with a capital S can be used in place of the struct name inside the implementation block. You can also just type out the struct name if you want to, but I recommend using self instead. Let's create our red fox like this. The scope operator in rust is double colons. And we use it to access parts of namespace like things.
We've already used the scope operator in use statements to access items inside of margin. Here we're using it to access an associated function of a struct. Once you have an instantiated value, you get and set fields and call methods with dot syntax as you do in most languages. methods are also defined in the implementation block. Methods always take some form of self is their first argument. At this point in the tutorial for most other languages, I would go for class inheritance for a little bit, or struct inheritance since that's what rust calls its classes.
It's a short discussion, though, because there is no struct inheritance. So wait, is rust an object oriented language or not? Well, it turns out that's a religious war question because there's no universally accepted definition of what an object oriented language is or isn't. And since the rest community doesn't do religious wars, nobody really cares what the answer is. The real question is why doesn't rust have struct inheritance The answer is because they chose a better way to solve the problem we wish inheritance solved, trains which is what we are going to talk about in the next video.