Skip to main content

Module strconv

Module strconv 

Source
Expand description

Routines for converting datum values to and from their string representation.

The functions in this module are tightly related to the variants of SqlScalarType. Each variant has a pair of functions in this module named parse_VARIANT and format_VARIANT. The type returned by parse functions, and the type accepted by format functions, will be a type that is easily converted into the Datum variant for that type. The functions do not directly convert from Datums to Strings so that the logic can be reused when Datums are not available or desired, as in the pgrepr crate.

The string representations used are exactly the same as the PostgreSQL string representations for the corresponding PostgreSQL type. Deviations should be considered a bug.

ModulesΒ§

proto_parse_error
Nested message and enum types in ProtoParseError.
proto_parse_hex_error
Nested message and enum types in ProtoParseHexError.

MacrosΒ§

bail πŸ”’

StructsΒ§

ListElementEscaper πŸ”’
ListElementWriter
A helper for format_list that formats a single list element.
MapElementEscaper πŸ”’
MapValueWriter
A helper for format_map that formats a single map value.
ParseError
An error while parsing an input as a type.
ProtoParseError
ProtoParseHexError
RangeElementWriter
A helper for format_range that formats a single record element.
RecordElementEscaper πŸ”’
RecordElementWriter
A helper for format_record that formats a single record element.

EnumsΒ§

ArrayParsingError πŸ”’
LeapSecond πŸ”’
Whether parsing rolls a :60 second into the next minute.
Nestable
Yes should be provided for types that will never return true for ElementEscaper::needs_escaping
ParseErrorKind
ParseHexError
TimeFields πŸ”’
Whether a TIME string has to name at least one time field.

ConstantsΒ§

MICROS_PER_SECOND πŸ”’
NANOS_PER_SECOND πŸ”’

TraitsΒ§

ElementEscaper

FunctionsΒ§

element_needs_escaping
Reports whether elem would be quoted by the list, map or record element escaper.
escape_elem πŸ”’
Escapes a list, record, or map element in place.
format_acl_item
Writes an acl_item to buf.
format_array
format_array_inner
format_bool
Writes a boolean value into buf.
format_bool_static
Like format_bool, but returns a string with a static lifetime.
format_bytes
format_date
Writes a Date to buf.
format_elems
Writes each elem into buf, separating the elems with sep.
format_float πŸ”’
format_float32
Writes an f32 to buf.
format_float64
Writes an f64 to buf.
format_int16
Writes an i16 to buf.
format_int32
Writes an i32 to buf.
format_int64
Writes an i64 to buf.
format_interval
format_jsonb
format_jsonb_pretty
format_legacy_vector
format_list
format_map
format_micros πŸ”’
Writes a microsecond fraction to buf with trailing zeros stripped, or nothing at all when it is zero.
format_mz_acl_item
Writes an mz_acl_item to buf.
format_mz_timestamp
Writes an mz_timestamp to buf.
format_numeric
format_range
Writes a Range to buf.
format_record
format_string
format_time
Writes a NaiveTime to buf.
format_timestamp
Writes a NaiveDateTime timestamp to buf.
format_timestamptz
Writes a DateTime<Utc> timestamp to buf.
format_uint16
Writes an u16 to buf.
format_uint32
Writes an u32 to buf.
format_uint64
Writes an u64 to buf.
format_uuid
lex_embedded_element πŸ”’
lex_quoted_element πŸ”’
lex_unquoted_element πŸ”’
parse_acl_item
Parses an AclItem from s.
parse_array
parse_array_inner πŸ”’
parse_bool
Parses a bool from s.
parse_bytes
parse_bytes_hex
parse_bytes_traditional
parse_date
Parses a Date from s.
parse_date_inner πŸ”’
parse_date_legacy
Parses a Date from s with the frozen legacy year-month-day interpretation of ambiguous dates.
parse_float πŸ”’
parse_float32
Parses an f32 from s.
parse_float64
Parses an f64 from s.
parse_int16
Parses an i16 from s.
parse_int32
Parses an i32 from s.
parse_int64
Parses an i64 from s.
parse_interval
parse
parse_interval_w_disambiguator
Parse an interval string, using an optional leading precision for time (H:M:S) and a specific mz_sql_parser::ast::DateTimeField to identify ambiguous elements. For more information about this operation, see the documentation on ParsedDateTime::build_parsed_datetime_interval.
parse_jsonb
parse_legacy_vector
parse_legacy_vector_inner
Parses PostgreSQL’s legacy whitespace-separated vector syntax (used in Materialize for int2vector). Unlike parse_array, this grammar has no token for NULL, which is why int2vector cannot represent NULL elements. See crate::scalar::Int2Vector.
parse_list
parse_list_inner πŸ”’
parse_map
parse_map_inner πŸ”’
parse_mz_acl_item
Parses an MzAclItem from s.
parse_mz_timestamp
Parses an mz_timestamp from s.
parse_mz_timestamp_legacy
Parses an mz_timestamp from s with the frozen legacy date parsing in its timestamp fallback.
parse_numeric
parse_oid
Parses an OID from s.
parse_oid_legacy
Parses an OID from s, accepting only the i32 range.
parse_pg_legacy_name
parse_range
parse_range_inner πŸ”’
parse_time
Parses a NaiveTime from s, using the following grammar.
parse_time_inner πŸ”’
parse_time_legacy
Parses a NaiveTime from s, resolving a string that names no time field at all to midnight.
parse_timestamp
Parses a NaiveDateTime from s.
parse_timestamp_inner πŸ”’
parse_timestamp_legacy
Parses a NaiveDateTime from s with the frozen legacy year-month-day interpretation of ambiguous dates.
parse_timestamp_string πŸ”’
Use the following grammar to parse s into:
parse_timestamptz
Parses a DateTime<Utc> from s. See mz_expr::scalar::func::timezone_timestamp for timezone anomaly considerations.
parse_timestamptz_inner πŸ”’
parse_timestamptz_legacy
Parses a DateTime<Utc> from s with the frozen legacy year-month-day interpretation of ambiguous dates.
parse_uint16
Parses an u16 from s.
parse_uint32
Parses an u32 from s.
parse_uint64
Parses an u64 from s.
parse_uuid
roll_over_leap_second πŸ”’
Postgres normalizes a parsed :60 second by rolling it into the next minute. chrono instead keeps a leap-second representation (nanos >= 1e9) that sorts before the following second while epoch-style conversions count it at or past that second, which breaks the monotonicity contracts persist filter pushdown derives ranges with. Roll it over at the parse boundary so the leap representation never enters a parsed timestamp. TIME keeps the leap representation: rolling it over would wrap to 00:00:00 and reverse its ordering, and the whole-second leap time is harmless.
round_to_micros πŸ”’
Rounds ts to microseconds, returning the value whose date and seconds are to be rendered plus the fraction to append to it.
split_nanos_to_micros πŸ”’
Splits a sub-second nanosecond count into a whole-second carry and the microsecond fraction to render, rounding half away from zero.