Deriving

Rust provides a handy attribute that allows you to access a number of commonly used traits without having to implement them yourself time and again. They are called using #[derive(Trait_Name)].

The traits available are as follows:

  • Clone: This creates a clone of the object
  • Copy: This creates a copy of the object
  • Debug: This provides debugging code
  • Default: This gives a useful default value for a type
  • Eq: Equality, this is similar to PartialEq except for all parameters within a struct
  • Hash: This is a hashable type
  • OrdOrder, these are the types that form a total order on all types
  • PartialEqPartial Equality, this only tests on a subset of the struct
  • PartialOrdPartial Order, values that can compared to create a sort order
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset