pub fn apply_str_float<T, F>(
lhs: StringAVT<'_, T>,
rhs: &[F],
op: ArithmeticOperator,
) -> Result<StringArray<T>, KernelError>Expand description
Applies an element-wise binary operation between a StringArray<T> and a slice of floating-point values,
producing a new StringArray<T>. Each operation is performed by interpreting the float as a finite
decimal string representation (f64 formatted with ryu), and applying string transformations accordingly.
Supported operations:
Add: Appends the stringified float to the string fromlhs.Subtract: Removes the first occurrence of the stringified float fromlhs, if present. If not found,lhsis returned unchanged.Multiply: Repeats thelhsstringNtimes, whereN = abs(round(rhs)) % (STRING_MULTIPLICATION_LIMIT + 1).Divide: Splits thelhsstring by the stringified float, and joins the segments using'|'. If the float pattern is not found, the original string is returned unchanged.
Null handling:
- If the
lhsvalue is null at an index, the result is null at that index. - The float operand cannot be null; the caller must guarantee its presence.
Output:
- A new
StringArray<T>with the same length aslhs. - The underlying byte storage is preallocated based on a prepass analysis of required capacity.
Errors:
- Returns
KernelError::LengthMismatchiflhsandrhslengths differ. - Returns
KernelError::UnsupportedTypeif the operator is not one of Add, Subtract, Multiply, Divide.
§Features
This function is only available when the str_arithmetic feature is enabled.
This kernel is optional as it pulls in external dependencies, and fits more niche use cases. It’s a good fit for flex-typing scenarios where users are concatenating strings and numbers, or working with semi-structured web content, string formatting pipelines etc.
§Safety
- Uses unchecked access and raw pointer copies for performance. Invariants around memory safety must hold.
- Assumes
rhscontains only finite floating-point values.