Rust์˜ enum ์†Œ๊ฐœ

Rust ์–ธ์–ด๋ฅผ ๋งค์ฃผ ๊ณต๋ถ€๋ฅผ ํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”, Rust์˜ ๋‹ค์–‘ํ•œ ๋งค๋ ฅ์ ์ธ ๊ธฐ๋Šฅ์ค‘์— ์ €๋Š” enum์ด ์ฐธ ๋งˆ์Œ์— ๋“ญ๋‹ˆ๋‹ค.

pub enum Response<T, E> {
   Ok(T),
   Error(E)
}

Result<T, E>๋ผ๋Š” ์—ด๊ฑฐํ˜•์€ Ok(T)์™€ Error(E)๋ผ๋Š” ์—ด๊ฑฐ ์œ ํ˜•์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š”๋ฐ์š”, ์‹ ๋ฐ•ํ•œ๊ฒƒ์€ Ok์ผ ๋•Œ T ํ˜•์˜ ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๊ณ , Error์ผ ๋•Œ E ํ˜•์˜ ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

fn main() {
    let ok_value: Response<i32, &str> = Response::Ok(312);
    let err_value: Response<i32, &str> = Response::Error("Error!");

    print(&ok_value);
    print(&err_value);
}

fn print(value: &Response<i32, &str>) {
    match value {
        Response::Ok(v) => println!("{}", v),
        Response::Error(message) => println!("{}", message),
    }
}

์ด๊ฒŒ ์ €์—๊ฒŒ๋Š” ์ƒ๋‹นํžˆ ๋งค๋ ฅ์ ์œผ๋กœ ๋ณด์—ฌ์„œ C#์—๋„ ๋„์ž…์ด ๋˜์—ˆ์Œ ํ•˜๋Š” ๋ฐ”๋žจ์ž…๋‹ˆ๋‹ค.

5๊ฐœ์˜ ์ข‹์•„์š”