pub struct ValueFormatter;Expand description
ValueFormatter provides cqlsh-compatible string formatting for CQL values
Implementations§
Source§impl ValueFormatter
impl ValueFormatter
Sourcepub fn is_null(value: &Value) -> bool
pub fn is_null(value: &Value) -> bool
Returns true when the value represents a genuine CQL NULL.
This is the authoritative null predicate used by output writers to decide
whether to emit an empty CSV field. It replaces the fragile
format_value(v) == "null" sentinel, which wrongly collapsed a literal
text value "null" to an empty field (issue #1499).
A genuine null in a frozen column is represented as
Value::Frozen(Box::new(Value::Null)) (which format_value renders as the
bare string "null"), so is_null unwraps Value::Frozen recursively
before checking for Value::Null. This restores the pre-#1499 CSV
null-output contract for frozen columns without re-introducing the original
bug: a literal text value Value::text("null") is NOT null and still emits
"null". Value::Null and Value::Frozen(..) are the only genuine-null
representations that format to the bare string "null" (a UDT/collection
with null members formats as {field: null}/[null], not "null").
Sourcepub fn format_into(value: &Value, out: &mut String)
pub fn format_into(value: &Value, out: &mut String)
Append the formatted string representation of value to out.
Byte-for-byte identical to format_value, but writes into a caller-owned
scratch buffer so hot loops (CSV rows) can reuse one allocation across all
cells instead of allocating a fresh String per cell (issue #1499). Scalar
hot paths are written directly; rarer complex types delegate to
format_value for a single append.
Sourcepub fn format_uuid_into(bytes: &[u8; 16], out: &mut String)
pub fn format_uuid_into(bytes: &[u8; 16], out: &mut String)
Encode a 16-byte UUID as lowercase hyphenated text into out using a hex
lookup table (no per-cell format! machinery). Shared by format_uuid
and the JSON writer (issue #1499).
Sourcepub fn format_value(value: &Value) -> String
pub fn format_value(value: &Value) -> String
Format a Value to its string representation according to the contract specification
§Contract Guarantees
- UUID/TimeUUID: lowercase hyphenated (e.g., “a8f167f0-ebe7-4f20-a386-31ff138bec3b”)
- Timestamps:
YYYY-MM-DD HH:MM:SS[.fff][+0000], default UTC - Collections: list
[a, b], set{a, b}, map{k: v} - Blob:
0x-prefixed lowercase hex - Boolean:
true/false - Numbers: standard Rust formatting, avoid scientific notation unless necessary