You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A rust struct is similar to a C struct or a C++ struct without methods. Simply a list of named fields. The syntax is best seen with an example:
This statement is misleading because it suggests that methods can not be defined for a struct, while methods can be defined via impl blocks. There is a brief mention of this possibility with:
Behaviour is defined by functions and those can be defined in traits and impls
However, this suggests the impls would define functions rather than methods, while in fact impls can define both.
For reference here is a short example outlining the type of functionality I am describing.
structExample{foo:i16,bar:i16,}implExample{fnbaz(&self) -> i16{self.foo + self.bar}}fnmain(){let ex = Example{foo:3,bar: -1,};println!("{}", ex.baz());}
This will print 2. I believe a section on this functionality should be added as it is critical to creating useful abstractions.
The text was updated successfully, but these errors were encountered:
In the section on data types it states:
A rust struct is similar to a C struct or a C++ struct without methods. Simply a list of named fields. The syntax is best seen with an example:
This statement is misleading because it suggests that methods can not be defined for a struct, while methods can be defined via impl blocks. There is a brief mention of this possibility with:
Behaviour is defined by functions and those can be defined in traits and impls
However, this suggests the impls would define functions rather than methods, while in fact impls can define both.
For reference here is a short example outlining the type of functionality I am describing.
This will print
2
. I believe a section on this functionality should be added as it is critical to creating useful abstractions.The text was updated successfully, but these errors were encountered: