Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
57
1
타입
애플리케이션 코드에서
anyhow
크레이트를 사용하면 오류 처리 코드를 간편하고 관용적으로 작성할 수
있다.
결정은 여러분의 몫이다. 단, 어떻게 결정하든지 타입 시스템으로 인코딩한다 (아이템
1
).
아이템
5
: 타입 변환을 이해하라
러스트에서 타입 변환은 다음과 같이 세 가지가 있다.
수동
:
From
Into
트레이트 구현으로 제공되는 사용자 정의 타입 변환
반자동
:
as
키워드를 이용한 값 사이의 명시적 캐스트
cast
자동
: 새로운 타입에 대한 암묵적인 강제 변환
coercion
이번 아이템에서는 첫 번째 유형인 수동 타입 변환 위주로 설명한다. 나머지 두 유형은 사용자
정의 타입 변환에 잘 사용하지 않는다. 하지만 몇 가지 예외가 있으므로 이 아이템의 마지막 절
에서 사용자 정의 타입에 대해 캐스팅과 강제 변환을 적용하는 방법도 간략히 소개한다.
참고로 다른 프로그래밍 언어와 달리 러스트는 숫자 타입에 대한 자동 변환을 제공하지 않는
다. 심지어 정수 타입 사이의 ‘안전한’ 변환도 지원하지 않는다.
오류가 발생하는 코드
let x: u32 = 2;
let y: u64 = x;
error[E0308]: mismatched types
--> src/main.rs:70:18
|
70 | let y: u64 = x;
| --- ^ expected ...
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