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

메서드

메서드는 함수와 유사하게 어노테이션됩니다:

struct Owner(i32);

impl Owner {
    // 독립형 함수처럼 라이프타임을 어노테이션합니다.
    fn add_one<'a>(&'a mut self) { self.0 += 1; }
    fn print<'a>(&'a self) {
        println!("`print`: {}", self.0);
    }
}

fn main() {
    let mut owner = Owner(18);

    owner.add_one();
    owner.print();
}

참고:

메서드