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

Function size

cel/src/functions.rs:76–84  ·  view source on GitHub ↗

Calculates the size of either the target, or the provided args depending on how the function is called. If called as a method, the target will be used. If called as a function, the first argument will be used. The following [`Value`] variants are supported: [`Value::List`] [`Value::Map`] [`Value::String`] [`Value::Bytes`] # Examples ```skip size([1, 2, 3]) == 3 ``` ```skip 'foobar'.size() == 6

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

Source from the content-addressed store, hash-verified

74/// 'foobar'.size() == 6
75/// ```
76pub fn size(ftx: &FunctionContext, This(this): This<Value>) -> Result<i64> {
77 let size = match this {
78 Value::List(l) => l.len(),
79 Value::Map(m) => m.map.len(),
80 Value::String(s) => s.len(),
81 value => return Err(ftx.error(format!("cannot determine the size of {value:?}"))),
82 };
83 Ok(size as i64)
84}
85
86/// Returns true if the target contains the provided argument. The actual behavior
87/// depends mainly on the type of the target.

Callers

nothing calls this directly

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected