Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
33
1
타입
표현식의 일부로 만들 수 있어서 이름을 붙일 필요가 없다.
입력 매개변수는
|param1, param2|
와 같이 파이프 (
|
)로 묶는다 (매개변수 타입은 대부분 컴파일러가
자동으로 추론할 수 있다 ).
주변 환경을 캡처
capture
10
할 수 있다.
let amount_to_add = 3;
let add_n = |y| {
// 클로저에서 `amount_to_add`를 캡처한다.
y + amount_to_add
};
let z = add_n(5);
assert_eq!(z, 8);
캡처의 작동 방식을 간단히 표현하면 다음 코드와 같다. 우선 컴파일러는 람다 표현식에서 언
급하는 환경을 구성하는 모든 부분에 대해 일회용 내부 타입을 생성한다. 그러고 나서 클로저
가 생성되는 시점에 앞서 만들어 둔 일회용 타입의 인스턴스를 생성해 환경값을 보관한다. 그
러다 클로저가 호출되면 해당 인스턴스를 컨텍스트에 추가해서 사용한다.
let amount_to_add = 3;
// 환경을 캡처하는 클로저를 *간단히* 표현하면 다음과 같다.
struct InternalContext<'a> {
// 캡처한 변수에 대한 레퍼런스
amount_to_add: &'a u32,
}
impl<'a> InternalContext<'a> {
fn internal_op(&self, y: ...
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