Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
128
이펙티브 러스트
니처가
drop
(
self
)
가 아닌
drop
(&
mut
self
)
다. 이 메서드는 객체를 이동시키지 않고 가변
레퍼런스 타입으로 받는다. 만약
Drop
::
drop
메서드가 일반 메서드처럼 작동한다면, 내부 상
태가 모두 정리되고 리소스가 해제된 후에도 객체를 계속 사용할 수 있다.
오류가 발생하는 코드
{
// 만약 `drop`을 호출할 수 있다면...
x.drop(); // (여기서 컴파일 오류가 발생한다.)
// 여전히 `x`를 사용할 수 있다.
x.0 += 1;
}
// 그렇다면 `x`가 스코프를 벗어나면 어떻게 될까?
이에 대해 컴파일러는 단순한 방식을 제공한다. 표준 라이브러리의
drop
()
함수를 통해 객체
를 직접 드롭할 수 있다. 이 함수의 인수는 실제로 이동되지만,
drop
(_
item
:
T
)
가 빈 본문인
중괄호 (
{ }
)로만 구현돼 있기 때문에 이동된 객체는 해당 스코프의 닫는 중괄호에 다다르면
드롭된다.
또한
drop
(&
mut
self
)
메서드의 시그니처에 반환 타입이 없다. 그래서 실패하더라도 그 사
실을 알릴 방법이 없다. 리소스 해제에 실패할 수 있다면 그 사실을 사용자가 알 수 있도록
Result
를 반환하는
release
메서드를 별도로 마련하는 것이 바람직하다.
이런 기술적인 세부 사항은 차치하더라도, 표준 라이브러리의 ...
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