MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / extract_keyword_args

Function extract_keyword_args

aiscript-vm/src/stdlib/serde.rs:190–220  ·  view source on GitHub ↗

Helper function to extract keyword arguments from args vector

(
    args: &[Value<'gc>],
)

Source from the content-addressed store, hash-verified

188
189// Helper function to extract keyword arguments from args vector
190fn extract_keyword_args<'gc>(
191 args: &[Value<'gc>],
192) -> Result<
193 (
194 Vec<Value<'gc>>,
195 std::collections::HashMap<String, Value<'gc>>,
196 ),
197 VmError,
198> {
199 let mut positional = Vec::new();
200 let mut keyword = std::collections::HashMap::new();
201 let mut i = 0;
202
203 while i < args.len() {
204 match (&args[i], args.get(i + 1)) {
205 (Value::String(key), Some(value)) if i < args.len() - 1 => {
206 // Check if this is a key-value pair for a named argument
207 if key.to_str().unwrap() == "pretty" {
208 keyword.insert("pretty".to_string(), *value);
209 i += 2;
210 continue;
211 }
212 }
213 _ => {}
214 }
215 positional.push(args[i]);
216 i += 1;
217 }
218
219 Ok((positional, keyword))
220}

Callers 2

serde_to_strFunction · 0.85
serde_to_fileFunction · 0.85

Calls 4

lenMethod · 0.80
to_strMethod · 0.80
pushMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected