Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
164
이펙티브 러스트
하지만 같은 시그니처라도 수명을 생략하면 오해를 불러 일으킬 수 있다.
pub fn find_one_item(items: &[Item]) -> ReferenceHolder {
// ...
}
여기서 반환 타입에 대한 수명 매개변수를 생략했기 때문에 이 코드를 읽는 사람은 여기에 수
명이 관련되어 있다는 사실을 놓칠 수 있다.
이럴 때는 익명 수명
anonymous
lifetime
(
'_
)을 사용해 생략된 수명이 있음을 표시한다. 그러면 수명
이름을 모두 나열하지 않아도 된다.
pub fn find_one_item(items: &[Item]) -> ReferenceHolder<'_> {
// ...
}
간단히 말해 컴파일러가
'_
마커가 있는 곳마다 고유한 수명 이름을 만들어 준다. 이렇게 만들
어진 이름은 우리가 명시적으로 지정하지 않는 각 지점에서 내부적으로 적절히 사용된다.
이 기능은 수명 생략 규칙이 적용되는 다른 경우에서도 유용하다. 예를 들어 다음과 같이
Debug
트레이트의
fmt
메서드를 선언할 때
Formatter
인스턴스의 수명이
&
self
와 다르다는
사실을 익명 수명으로 표현한다. 여기서 수명 이름 자체는 중요하지 않기 때문이다.
pub trait Debug {
fn fmt(&self, f: &mut Formatter<'_>) ...
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