(&mut self, call: messages::InitCall)
| 498 | } |
| 499 | |
| 500 | fn handle_init(&mut self, call: messages::InitCall) -> Result<Configuration, Error> { |
| 501 | use options::Value as OValue; |
| 502 | use serde_json::Value as JValue; |
| 503 | |
| 504 | // Match up the ConfigOptions and fill in their values if we |
| 505 | // have a matching entry. |
| 506 | for (name, option) in self.options.iter() { |
| 507 | let json_value = call.options.get(name); |
| 508 | let default_value = option.default(); |
| 509 | |
| 510 | let option_value: Option<options::Value> = match (json_value, default_value) { |
| 511 | (None, None) => None, |
| 512 | (None, Some(default)) => Some(default.clone()), |
| 513 | (Some(JValue::Array(a)), _) => match a.first() { |
| 514 | Some(JValue::String(_)) => Some(OValue::StringArray( |
| 515 | a.iter().map(|x| x.as_str().unwrap().to_string()).collect(), |
| 516 | )), |
| 517 | Some(JValue::Number(_)) => Some(OValue::IntegerArray( |
| 518 | a.iter().map(|x| x.as_i64().unwrap()).collect(), |
| 519 | )), |
| 520 | _ => panic!("Array type not supported for option: {}", name), |
| 521 | }, |
| 522 | (Some(JValue::String(s)), _) => Some(OValue::String(s.to_string())), |
| 523 | (Some(JValue::Number(i)), _) => Some(OValue::Integer(i.as_i64().unwrap())), |
| 524 | (Some(JValue::Bool(b)), _) => Some(OValue::Boolean(*b)), |
| 525 | _ => panic!("Type mismatch for option {}", name), |
| 526 | }; |
| 527 | |
| 528 | self.option_values.insert(name.to_string(), option_value); |
| 529 | } |
| 530 | Ok(call.configuration) |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | impl<S> HookBuilder<S> |
no test coverage detected