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

Method invoke

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

Source from the content-addressed store, hash-verified

27 }
28
29 fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
30 let arg = &args[0];
31 let value: i64;
32 if arg.is_string() {
33 let input = arg.as_str().ok_or(DscError::FunctionArg("int".to_string(), t!("functions.int.invalidInput").to_string()))?;
34 let result = input.parse::<f64>().map_err(|_| DscError::FunctionArg("int".to_string(), t!("functions.int.parseStringError").to_string()))?;
35 value = NumCast::from(result).ok_or(DscError::FunctionArg("int".to_string(), t!("functions.int.castError").to_string()))?;
36 } else if arg.is_number() {
37 value = arg.as_i64().ok_or(DscError::FunctionArg("int".to_string(), t!("functions.int.parseNumError").to_string()))?;
38 } else {
39 return Err(DscError::FunctionArg("int".to_string(), t!("functions.invalidArgType").to_string()));
40 }
41 Ok(Value::Number(value.into()))
42 }
43}
44
45#[cfg(test)]

Callers

nothing calls this directly

Calls 2

FunctionArgEnum · 0.85
as_strMethod · 0.80

Tested by

no test coverage detected