Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
242
이펙티브 러스트
아이템
23
: 와일드카드 임포트를 쓰지 마라
러스트에서는 다른 크레이트나 모듈에 있는 이름 있는 아이템을
use
문으로 가져와서, 그 이름
을 로컬 모듈의 코드에서 본래 소속
qualification
을 명시하지 않고 사용할 수 있다.
와일드카드 임포
wildcard
import
(또는
글롭 임포트
glob
import
)
use
somecrate
::
module
::*
형식의 구문으로서,
여기서 명시한 모듈에 속한 모든 공개 심벌
symbol
을 로컬 네임스페이스에 추가한다.
아이템
21
에서 설명한 것처럼 외부 크레이트는 마이너 버전 업그레이드로
API
에 항목을 새로
추가할 수 있다. 이는
하위 호환 변경
backward
compatible
change
에 해당하기 때문이다.
이 두 가지가 결합하면 의존성을 해치지 않는 변경이 오히려 코드를 손상시키는 문제가 발생할
수 있다. 만약 이러한 의존성에 의해 새로 추가한 심벌이 기존에 사용하고 있던 이름과 충돌하
면 어떻게 될까?
다음과 같이 단순한 코드에서는 문제가 되지 않는다. 와일드카드 임포트를 통해 가져온 이름들
은 우선순위가 가장 낮기 때문에, 기존 코드에 있던 이름이 우선 적용된다.
use bytes::*;
// 로컬에 있는 `Bytes` 타입은 `bytes::Bytes`와 충돌하지 않는다.
struct ...
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