| 181 | Ok(res) |
| 182 | } |
| 183 | fn to_field(from: Vec<IDLValue>) -> Result<Vec<IDLField>> { |
| 184 | let mut fs = Vec::with_capacity(from.len()); |
| 185 | for v in from.into_iter() { |
| 186 | match v { |
| 187 | IDLValue::Record(f) => match &f[..] { |
| 188 | [IDLField { |
| 189 | val: IDLValue::Text(key), |
| 190 | .. |
| 191 | }, IDLField { val, .. }] => { |
| 192 | let id = match key.parse::<u32>() { |
| 193 | Ok(id) => Label::Id(id), |
| 194 | Err(_) => Label::Named(key.to_string()), |
| 195 | }; |
| 196 | fs.push(IDLField { |
| 197 | id, |
| 198 | val: val.clone(), |
| 199 | }) |
| 200 | } |
| 201 | _ => return Err(anyhow!("expect function to return record {{ key; value }}")), |
| 202 | }, |
| 203 | _ => return Err(anyhow!("expect function to return record {{ key; value }}")), |
| 204 | } |
| 205 | } |
| 206 | fs.sort_unstable_by_key(|IDLField { id, .. }| id.get_id()); |
| 207 | check_unique(fs.iter().map(|f| &f.id))?; |
| 208 | Ok(fs) |
| 209 | } |
| 210 | |
| 211 | fn map(helper: &MyHelper, vs: Vec<IDLValue>, func: &str) -> Result<Vec<IDLValue>> { |
| 212 | let mut new_helper = helper.spawn(); |