Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
62
이펙티브 러스트
이 제네릭 버전은 다음과 같이 호출할 수 있다.
if is_iana_reserved(42) {
// ...
}
이런 트레이트 바운드는
From
<
T
>
의 반사적 트레이트 구현이 더 적합하다. 다시 말해 이런 제
네릭 함수는 이미
IanaAllocated
인스턴스인 항목을 처리하므로 변환할 필요가 없다.
또한 러스트 코드가 타입끼리 암묵적으로 변환되는 것처럼 보이는 이유와 그 방법도 이 패턴을
통해 알 수 있다.
From
<
T
>
구현과
Into
<
T
>
트레이트 바운드를 조합하면 호출한 측에서 마술
처럼 변환되는 것처럼 보이면서 실제로는 안전하고 명시적인 변환을 수행하는 코드가 만들어
진다. 이 패턴은 레퍼런스 타입과 관련 변환 트레이트가 결합될 때 더욱 강력한 힘을 발휘한다
(자세한 내용은 아이템
8
에서 다룬다).
캐스트
러스트에서 제공하는
as
키워드를 사용하면 두 타입 사이를 명시적으로 캐스트
cast
할 수 있다.
as
키워드로 변환할 수 있는 타입은 사실 많지 않다. 사용자 정의 타입 중에서는
C
언어와 비
슷한 (즉, 연관된 정숫값만으로 구성된 )
enum
뿐이다. 그래도 일반 정수 변환에 대해서는
as
지원하고 있어서
into
()
대신 사용할 수 있다.
let x: u32 = 9;
let y = x as u64;
let z: u64 = x.into(); ...
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