Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
103
1
타입
마지막으로 반복문에서 탐색했던 모든 항목을 새로운 컬렉션에 누적하는 메서드도 있다. 그중
에서 가장 중요한 메서드는
collect
()
로,
FromIterator
트레이트를 구현하는 모든 컬렉션
타입의 인스턴스를 새로 만드는 데 사용한다.
FromIterator
트레이트는
Vec
,
HashMap
,
BTreeSet
등과 같은 모든 표준 라이브러리 컬렉
션 타입에 대해 구현되어 있다. 그런데 이처럼 모든 곳에 구현돼 있는 만큼 타입을 명시해야 하
는 경우가 많다. 그러지 않으면 컴파일러로서는 (예를 들어 )
Vec
<
i32
>
HashSet
<
i32
>
에서 어느 것을 가리키는지 알 수 없기 때문이다.
use std::collections::HashSet;
// 짝수 컬렉션을 만든다. 이때 타입을 반드시 명시해야 한다.
// 두 타입 모두 표현식이 동일하기 때문이다.
let myvec: Vec<i32> = (0..10).into_iter().filter(|x| x % 2 == 0).collect();
let h: HashSet<i32> = (0..10).into_iter().filter(|x| x % 2 == 0).collect();
이 예제를 통해 범위 표현식을 이용해 반복 대상이 될 데이터의 초깃값을 생성하는 방법도 볼
수 있다.
이보다는 덜 알려져 ...
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