Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

주석

모든 프로그래머는 자신의 코드를 이해하기 쉽게 만들려고 노력하지만, 때로는 추가 설명이 필요합니다. 이런 경우 프로그래머는 소스 코드 안에 주석(comments) 을 남깁니다. 컴파일러는 이 주석을 무시하지만, 소스 코드를 읽는 사람에게는 유용할 수 있습니다.

다음은 간단한 주석입니다.

#![allow(unused)]
fn main() {
// hello, world
}

러스트에서 관용적인 주석 스타일은 슬래시 두 개로 주석을 시작하고, 그 주석은 줄 끝까지 이어집니다. 한 줄을 넘어가는 주석은 다음처럼 각 줄마다 // 를 넣어야 합니다.

#![allow(unused)]
fn main() {
// So we're doing something complicated here, long enough that we need
// multiple lines of comments to do it! Whew! Hopefully, this comment will
// explain what's going on.
}

주석은 코드가 있는 줄의 끝에 둘 수도 있습니다.

파일명: src/main.rs

fn main() {
    let lucky_number = 7; // I'm feeling lucky today
}

하지만 보통은 주석을 설명하려는 코드 위의 별도 줄에 두는 형식을 더 자주 보게 됩니다.

파일명: src/main.rs

fn main() {
    // I'm feeling lucky today
    let lucky_number = 7;
}

러스트에는 또 다른 종류의 주석인 문서화 주석도 있습니다. 이것은 14장의 “Crates.io에 크레이트 배포하기” 절에서 다룹니다.