Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
38
이펙티브 러스트
마커 트레이트에는 정의된 함수가 없지만 이 트레이트를 구현한다고 선언해 두면 유용하다. 이
는 마치 구현하는 측에서 ‘내 구현은 안정적으로 정렬됨을 엄숙히 선언합니다’라고 보장하는 것
과 같다. 그러면 안정적인 정렬이 필요한 코드에서
StableSort
트레이트 바운드를 지정함으
로써, 이러한 불변성을 유지하는 신뢰 관계를 형성할 수 있다. 따라서
트레이트 함수 시그니처로
표현할 수 없는 동작은 마커 트레이트로 구분하라.
트레이트를 통해 동작을 러스트의 타입 시스템 안에 캡슐화했다면, 다음과 같이 두 가지 방식
으로 활용할 수 있다.
트레이트 바운드:
제네릭 데이터 타입이나 함수로 전달할 수 있는 타입을 컴파일 타임에 제한한다.
트레이트 객체:
함수에 전달하거나 함수에 저장할 수 있는 타입을 런타임에 제한한다.
이제부터 이 두 가지 방식을 하나씩 살펴본다. 아이템
12
에서는 두 가지 방식의 장단점에 대해
자세히 설명한다.
트레이트 바운드
트레이트 바운드
trait
bound
는 타입
T
를 매개변수로 받도록 정의한 제네릭 코드에서, 타입
T
가 특
정한 트레이트를 구현하는 경우에만 받을 수 있게 제한한다. 제네릭 코드에 트레이트 바운드
가 지정돼 있다면 그 제네릭 구현은 지정된 트레이트에 정의된 함수를 사용할 수 있다. 컴파일
검사를 문제없이 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

이펙티브 타입스크립트

이펙티브 타입스크립트

Dan Vanderkam
파이썬으로 살펴보는 아키텍처 패턴

파이썬으로 살펴보는 아키텍처 패턴

오현석, 해리 퍼시벌, 밥 그레고리

Publisher Resources

ISBN: 9791169212946