ํŠธ๋ ˆ์ž‡(Trait)

ํŠธ๋ ˆ์ž‡์€ ํƒ€์ž…์„ ์ถ”์ƒํ™” ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค์™€ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค:

trait Pet {
    /// Return a sentence from this pet.
    fn talk(&self) -> String;

    /// Print a string to the terminal greeting this pet.
    fn greet(&self);
}
This slide and its sub-slides should take about 15 minutes.
  • ํŠธ๋ ˆ์ž‡์€ ํ•ด๋‹น ํŠธ๋ ˆ์ž‡์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ํƒ€์ž…์ด ๊ฐ€์ ธ์•ผ ํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

  • In the โ€œGenericsโ€ segment, next, we will see how to build functionality that is generic over all types implementing a trait.