Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
188
이펙티브 러스트
대여 검사기가 출력하는 오류에 대처하는 방법은 다음과 같이 다양하다.
{ ... }
스코프를 추가해서 값의 수명 범위를 줄인다.
– 값에 대해 이름 있는 로컬 변수를 추가해서 스코프가 끝날 때 값의 수명이 끝나게 한다.
– 임시 로컬 변수를 추가해서 대여 검사기가 지적하는 문제의 범위를 좁힌다.
러스트의 스마트 포인터 타입을 이용하면 대여 검사기의 지적을 피할 수 있어서 서로 연결된 데이터 구
조에 유용하다.
그렇지만 자기 참조 데이터 구조는 러스트에서도 여전히 다루기 어렵다.
아이템
16
:
unsafe
코드 작성을 자제하라
런타임 오버헤드 없이 메모리 안전성을 보장한다는 점은 다른 주류 언어에는 없는 러스트 언
어만의 장점이다. 하지만 이를 위해 치러야 할 대가가 있다. 대여 검사기를 잘 달래고(아이템
15
), 사용할 레퍼런스 타입을 정확히 지정하기 위해(아이템
8
) 코드를 재구성할 일이 많아
진다.
안전하지 않은 러스트
unsafe
Rust
란 메모리 안전 관련 제약 조건과 그에 따른 보장 사항을 희생한,
러스트 언어의 상위 집합이다. 코드 블록 앞에
unsafe
키워드를 붙이면 안전하지 않은 모드로
전환되어 일반 러스트에서는 허용되지 않던 것을 할 수 있다. 특히 예전
C
언어의 포인터에서
보던 원시 포인터를 사용할 수 있다. 이러한 원시 포인터는 대여 규칙이 적용되지 않아서 포인
터를 역참조할 때마다 해당 포인터가 가리키는 메모리의 유효성을 프로그래머가 직접 보장해
야 한다.
이 아이템에서 ...
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