MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / uint

Function uint

cel/src/functions.rs:177–196  ·  view source on GitHub ↗

Performs a type conversion on the target.

(ftx: &FunctionContext, This(this): This<Value>)

Source from the content-addressed store, hash-verified

175
176// Performs a type conversion on the target.
177pub fn uint(ftx: &FunctionContext, This(this): This<Value>) -> Result<Value> {
178 Ok(match this {
179 Value::String(v) => v
180 .parse::<u64>()
181 .map(Value::UInt)
182 .map_err(|e| ftx.error(format!("string parse error: {e}")))?,
183 Value::Float(v) => {
184 if v > u64::MAX as f64 || v < u64::MIN as f64 {
185 return Err(ftx.error("unsigned integer overflow"));
186 }
187 Value::UInt(v as u64)
188 }
189 Value::Int(v) => Value::UInt(
190 v.try_into()
191 .map_err(|_| ftx.error("unsigned integer overflow"))?,
192 ),
193 Value::UInt(v) => Value::UInt(v),
194 v => return Err(ftx.error(format!("cannot convert {v:?} to uint"))),
195 })
196}
197
198// Performs a type conversion on the target.
199pub fn int(ftx: &FunctionContext, This(this): This<Value>) -> Result<Value> {

Callers

nothing calls this directly

Calls 4

UIntClass · 0.85
mapMethod · 0.80
errorMethod · 0.80
try_intoMethod · 0.80

Tested by

no test coverage detected