Skip to main content

compare

Function compare 

Source
pub fn compare(left: &Value, right: &Value) -> Result<Ordering, DataError>
Expand description

Returns how left orders against right.

The order is types.md‘s, structural and total over each data type: numbers by value, text by code point and bytes by byte, false before true; lists, tuples and records element by element in order, with a proper prefix first; enum values by their constructors’ declaration order, then by payload; dictionaries as their entry lists in key order would, and sets as their sorted elements would; durations and instants chronologically.

The two values must be of one type. Reaching a value that is not data is DataError::NotData, and two values of different shapes is DataError::Mismatch; a checked program reaches neither.

Two records or two enum values of different declarations are of different shapes. The walk keeps the aggregates it is inside on a stack on the heap, so a value nested deeper than the native stack is compared like any other.

§Errors

DataError::NotData on reaching a value that is not data, and DataError::Mismatch on two values of different shapes.