Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
47
1
타입
기억할 사항
Option
Result
변환을 익히고, 가급적
Option
보다는
Result
를 사용하라. 레퍼런스 관련 변환이 필
요하다면
.as_ref()
를 사용하라.
Option
Result
에 대해 명시적인
match
연산보다는
Option
Result
변환을 사용하라.
특히 이러한 변환을 사용해 결과 타입을 물음표 연산자를 적용할 수 있는 형태로 바꿔라.
아이템
4
: 가급적 관용적인
Error
타입을 사용하라
아이템
3
에서는 표준 라이브러리에서 제공하는
Option
Result
타입의 변환 메서드를 사용
해 물음표 연산자 결과 타입을 간결하고 관용적으로 표현하는 방법을 설명했다. 이번에는 지난
아이템에서 설명하지 않았던,
Result
<
T
,
E
>
의 두 번째 타입 인수인
E
로 전달되는 다양한 오
류 타입을 처리하는 최선의 방법을 알아본다.
이 방법은 오류 타입이 다양한 경우에만 적용할 수 있다. 함수에서 발생하는 다양한 오류를 모
두 한 가지 타입으로 표현할 수 있다면, 그냥 그 타입으로 반환하면 된다. 반면 오류 타입이 다
양하다면 각 타입의 하위 오류 타입 정보의 보존 여부를 결정해야 한다.
Error
트레이트
항상 표준 트레이트 (아이템
10
)부터 찾아보는 것이 바람직하다. 이번 아이템에서 설명하는 오
류 타입 처리와 관련된 표준 트레이트로는
std
::
error
::
Error
가 있다.
Result
E
타입 매
개변수가 반드시
Error
를 구현하는 타입이어야 하는 것은 아니지만, 그렇게 하면 래퍼
wrapper ...
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