Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
70
이펙티브 러스트
컴파일러가 알려 주기 때문에 간단히 해결할 수 있다. 그보다 더 큰 문제는 내부 타입에 대한
트레이트 구현이 사라진다는 것이다. 뉴타입은 말그대로 새로운 타입이므로 기존 내부 구현이
적용되지 않는다.
파생 가능한
derivable
트레이트를 뉴타입으로 선언하면 수많은
derive
구문으로 뒤덮인다.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct NewType(InnerType);
그런데 좀 더 정교한 트레이트에서 내부 타입에 대한 구현을 복구하려면 이를 포워딩
forwarding
기 위한 보일러플레이트 코드가 필요하다. 예를 들면 다음과 같다.
use std::fmt;
impl fmt::Display for NewType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
self.0.fmt(f)
}
}
아이템
7
: 복잡한 타입에는 빌더를 적용하라
이번에는 복잡한 데이터 구조체의 인스턴스를 쉽게 생성할 수 있도록 빌더
builder
타입을 함께 지
정하는 빌더 패턴을 알아본다.
러스트에서 구조체의 인스턴스를 생성하려면 필드를 모두 채워야 한다. 이처럼 초기화되지 않
은 값이 존재할 수 없기 때문에 ...
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