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

Function string

cel/src/functions.rs:143–156  ·  view source on GitHub ↗

Performs a type conversion on the target. The following conversions are currently supported: `string` - Returns a copy of the target string. `timestamp` - Returns the timestamp in RFC3339 format. `duration` - Returns the duration in a string formatted like "72h3m0.5s". `int` - Returns the integer value of the target. `uint` - Returns the unsigned integer value of the target. `float` - Returns the

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

Source from the content-addressed store, hash-verified

141// * `float` - Returns the float value of the target.
142// * `bytes` - Converts bytes to string using from_utf8_lossy.
143pub fn string(ftx: &FunctionContext, This(this): This<Value>) -> Result<Value> {
144 Ok(match this {
145 Value::String(v) => Value::String(v.clone()),
146 #[cfg(feature = "chrono")]
147 Value::Timestamp(t) => Value::String(t.to_rfc3339().into()),
148 #[cfg(feature = "chrono")]
149 Value::Duration(v) => Value::String(crate::duration::format_duration(&v).into()),
150 Value::Int(v) => Value::String(v.to_string().into()),
151 Value::UInt(v) => Value::String(v.to_string().into()),
152 Value::Float(v) => Value::String(v.to_string().into()),
153 Value::Bytes(v) => Value::String(Arc::new(String::from_utf8_lossy(v.as_slice()).into())),
154 v => return Err(ftx.error(format!("cannot convert {v:?} to string"))),
155 })
156}
157
158pub fn bytes(value: Arc<String>) -> Result<Value> {
159 Ok(Value::Bytes(value.as_bytes().to_vec().into()))

Callers

nothing calls this directly

Calls 4

StringClass · 0.85
format_durationFunction · 0.85
cloneMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected