let mut id = Err(SolveRequestError::MissingId);
let mut size = Err(SolveRequestError::MissingSize);
let mut fixed_queens = vec![];
for (key, value) in query.map(|item| item.key_value_decoded()) {
match key.as_str() {
"id" => {
if id.is_ok() {
id = Err(SolveRequestError::MoreThanOneId)
} else {
id = str::parse(&value)
.map_err(|why| SolveRequestError::FailedToParseId(why))
}
}
"size" => {
if size.is_ok() {
size = Err(SolveRequestError::MoreThanOneSize)
} else {
size = str::parse(&value)
.map_err(|why| SolveRequestError::FailedToParseSize(why))
}
}
"queen" => {
if let Some((x_coord, y_coord)) = value.split_once(':') {
let x_coord = x_coord
.parse()
.map_err(SolveRequestError::FailedToParseQueenCoordinates)?;
let y_coord = y_coord
.parse()
.map_err(SolveRequestError::FailedToParseQueenCoordinates)?;
fixed_queens.push((x_coord, y_coord));
} else {
return Err(SolveRequestError::MissingColonInQueenCoordinates);
}
}
_ => {}
}
}
Ok(SolveRequest {
id: id?,
size: size?,
fixed_queens,
})