programming:rust

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
programming:rust [2020/12/13 18:14] – [Traits] mhprogramming:rust [2020/12/13 18:21] – [Traits] mh
Line 494: Line 494:
 </code> </code>
  
-Each type implementing the ''Summary'' trait must define it's own custom behavior for the body of the ''summarize'' method. The compiler will enforce this.+Each type implementing the ''Summary'' trait must define it's own custom behavior for the body of the ''summarize'' method. The compiler will enforce this. Note that instead of a '';'' semicolon a default behavior could be set on the trait declaration within ''{}'' curly brackets. 
 + 
 +To implement a trait on a type : 
 + 
 +<code rust> 
 +impl Summary for SomeStruct { 
 +    fn summarize(&self) -> String { 
 +        //some code 
 +    } 
 +
 +</code> 
 + 
 +If the trait had a default behavior, this implementation will override it.
 ===== Misc ===== ===== Misc =====
  
  • programming/rust.txt
  • Last modified: 2021/05/25 22:07
  • by mh