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>)
| 141 | // * `float` - Returns the float value of the target. |
| 142 | // * `bytes` - Converts bytes to string using from_utf8_lossy. |
| 143 | pub 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 | |
| 158 | pub fn bytes(value: Arc<String>) -> Result<Value> { |
| 159 | Ok(Value::Bytes(value.as_bytes().to_vec().into())) |
nothing calls this directly
no test coverage detected