Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
40
이펙티브 러스트
와 비슷하다. 러스트에서 내부적으로
vtable
을 이용한다는 점도
C
++와 거의 비슷하다.
이런 동적인 특성 때문에 트레이트 객체를 레퍼런스 (예:
&
dyn
Trait
)나 포인터 (예:
Box
<
dyn
Trait
>
) 등을 통해 간접적으로 처리해야 한다. 컴파일 시점에는 트레이트를 구현하는 객체의
크기를 알 수 없기 때문이다 (거대한
struct
일 수도 있고, 조그만
enum
일 수도 있다 ). 따라서
원시 트레이트 객체를 할당하는 데 필요한 공간 크기를 정확히 알 방법이 없다.
객체의 크기를 정확히 모른다는 말은 트레이트 객체로 사용되는 트레이트가
Self
타입을 반환
하는 함수를 가질 수 없거나, 메서드가 호출되는 객체인 수신자
receiver
말고는
Self
를 사용하는
인수를 가질 수 없다는 뜻이기도 하다. 그 이유는 트레이트 객체를 사용하도록 사전에 컴파일
된 코드는
Self
가 얼마나 큰지 전혀 알 수 없기 때문이다.
fn
some
_
fn
<
T
>(
t
:
T
)
와 같은 제네릭 함수를 가진 트레이트는 존재할 수 있는 모든
T
타입에
대해 구현할 수 있는 함수가 무한하다. 트레이트 바운드로 사용할 거라면 그래도 괜찮다. 호출
될 가능성이 있는 제네릭 함수가 무한히 많더라도, 컴파일 타임에 실제로 호출되는 제네릭 함
수는 유한하기 때문이다. 하지만 트레이트 객체는 그렇지 않다. 컴파일 타임에 코드를 생성할
때, 런타임에 올 수 있는 모든
T
를 처리할 수 있게 만들어야 하기 때문이다.
Self
와 제네릭 함수를 사용할 수 없다는 제약 ...
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