MCPcopy Create free account
hub / github.com/PowerShell/DSC / invoke

Method invoke

lib/dsc-lib/src/functions/first.rs:28–46  ·  view source on GitHub ↗
(&self, args: &[Value], _context: &Context)

Source from the content-addressed store, hash-verified

26 }
27
28 fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
29 debug!("{}", t!("functions.first.invoked"));
30
31 if let Some(array) = args[0].as_array() {
32 if array.is_empty() {
33 return Err(DscError::Parser(t!("functions.first.emptyArray").to_string()));
34 }
35 return Ok(array[0].clone());
36 }
37
38 if let Some(string) = args[0].as_str() {
39 if string.is_empty() {
40 return Err(DscError::Parser(t!("functions.first.emptyString").to_string()));
41 }
42 return Ok(Value::String(string.chars().next().unwrap().to_string()));
43 }
44
45 Err(DscError::Parser(t!("functions.first.invalidArgType").to_string()))
46 }
47}
48
49#[cfg(test)]

Callers

nothing calls this directly

Calls 3

as_strMethod · 0.80
is_emptyMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected