MCPcopy Create free account
hub / github.com/dfinity/ic-repl / to_field

Function to_field

src/selector.rs:183–209  ·  view source on GitHub ↗
(from: Vec<IDLValue>)

Source from the content-addressed store, hash-verified

181 Ok(res)
182}
183fn 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
211fn map(helper: &MyHelper, vs: Vec<IDLValue>, func: &str) -> Result<Vec<IDLValue>> {
212 let mut new_helper = helper.spawn();

Callers 1

projectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected