코드 4-27 전달한 매개변수에 따라 다른 질문 반환하기
async fn get_questions(
params: HashMap<String, String>,
store: Store,
) -> Result<impl warp::Reply, warp::Rejection> {
if !params.is_empty() {
let pagination = extract_pagination(params)?;
let res: Vec<Question> = store.questions.values().cloned().collect();
let res = &res[pagination.start..pagination.end];
Ok(warp::reply::json(&res))
} else {
let res: Vec<Question> = store.questions.values().cloned().collect();
Ok(warp::reply::json(&res))
}
let mut start = 0;
if let Some(n) = params.get("start") {
start = n.parse::<usize>().expect("Could not parse start");
}
println!("{}", start);