더북(TheBook)

코드 4-19 start를 출력하여 구조 알아보기

async fn get_questions(
    params: HashMap<String, String>,
    store: Store,
) -> Result<impl warp::Reply, warp::Rejection> {

    if let Some(n) = params.get("start") {
        println!("{}", n);
    }
    match params.get("start") {
        Some(start) => println!("{}", start),
        None => println!("No start value"),
    }
    ...
}
...

짧은 버전을 풀어 쓰면 다음과 같다. HashMapstart 키에 대한 Some 값이 있으면 Some으로 값을 추출하고 변수 n을 만든다. HashMapstart 키가 없으면 if는 실패하고 컴파일러는 다음 행으로 넘어간다.