Skip to content

Commit

Permalink
handle numeric strings for ids
Browse files Browse the repository at this point in the history
mitigates rust-lang#360 (for numeric strings)
  • Loading branch information
Trolldemorted committed Jun 30, 2017
1 parent ac8e0a3 commit a7556f6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ macro_rules! messages {
});
}

let id = ls_command.get("id").and_then(|id| id.as_u64()).map(|id| id as usize);
let id_value = ls_command.get("id").unwrap();
let mut id: Option<usize> = None;
if id_value.is_u64() {
id = Some(ls_command.get("id").unwrap().as_u64().unwrap() as usize);
} else if id_value.is_string() {
id = Some(usize::from_str_radix(id_value.as_str().unwrap(), 10).unwrap());
} else {
return Err(ParseError::new(ErrorKind::InvalidData, "Id is not a number or numeric string", id))
}

if let Some(v) = ls_command.get("method") {
if let Some(name) = v.as_str() {
Expand Down

0 comments on commit a7556f6

Please sign in to comment.