Daily Rust Study - variables, todo

Koowater·2024년 8월 8일
0

variables

  • Rust에서 변수는 기본적으로 값이 바인딩된 경우 변경 불가능하다. (immutable)
  • 값을 변경하기 위해선 mutable하게 변수를 선언하고 값을 바인딩해야 한다.
    let mut a_number = 10;

variable shadowing


todo! macro

  • Rust에서는 완성되지 않은 기능을 명시할 때 사용된다. 컴파일러는 컴파일 시 todo! macro에서 아직 구현되지 않은 기능이 있다고 패닉을 발생시킨다.

  • 예제코드

    fn do_something_awesome(x: i16){
    	println!("This function will do something awesome, but not implemented yet!\nJust print {}", x);
    	todo!("Please implement me...")
    }
    
    fn main(){
    	let a_number = 8;
    	do_something_awesome(a_number);
    }
  • 컴파일 결과

    PS C:\workspace\rust-tutorial\projects\test_todo_macro> cargo run
       Compiling test_todo_macro v0.1.0 (C:\workspace\rust-tutorial\projects\test_todo_macro)
        Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s
         Running `target\debug\test_todo_macro.exe`
    This function will do something awesome, but not implemented yet!
    Just print 8
    thread 'main' panicked at src/main.rs:3:5:
    not yet implemented: Please implement me...
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    error: process didn't exit successfully: `target\debug\test_todo_macro.exe` (exit code: 101)
profile
Speech to Text를 공부하고 있습니다.

0개의 댓글