Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Codec catalog

Generated rustdoc: https://docs.rs/babar/latest/babar/codec/index.html

See also: Book Chapter 10 — Custom codecs.

Every codec babar ships, grouped by module. OIDs are the Postgres type OIDs the codec advertises in Bind / RowDescription. All codecs use the binary wire format unless noted.

babar::codec (always on)

Postgres typeOIDRust typeCodec valueModule
int2 / smallint21i16int2primitive
int4 / integer23i32int4primitive
int8 / bigint20i64int8primitive
float4 / real700f32float4primitive
float8 / double precision701f64float8primitive
bool16boolboolprimitive
text25Stringtextprimitive
varchar1043Stringvarcharprimitive
bpchar / char(n)1042Stringbpcharprimitive
bytea17Vec<u8>byteaprimitive
any (NULL-aware wrapper)n/aOption<T>nullable(C)nullable
T[]array OIDVec<T>array(C)array (feature array)

Codec constants are lowercase to match Postgres type names — int4, text, bool shadow the Rust primitives inside babar::codec. That’s deliberate; import the constants explicitly (use babar::codec::{int4, text};) and the prim names remain visible elsewhere.

Optional types — feature-gated

Postgres typeOIDRust typeCodec valueModuleFeature
uuid2950uuid::Uuiduuiduuiduuid
date1082time::Datedatetimetime
time1083time::Timetimetimetime
timestamp1114time::PrimitiveDateTimetimestamptimetime
timestamptz1184time::OffsetDateTimetimestamptztimetime
date1082chrono::NaiveDatechrono_datechronochrono
time1083chrono::NaiveTimechrono_timechronochrono
timestamp1114chrono::NaiveDateTimechrono_timestampchronochrono
timestamptz1184chrono::DateTime<Utc>chrono_timestamptzchronochrono
interval1186babar::codec::Intervalintervalintervalinterval
numeric1700rust_decimal::Decimalnumericnumericnumeric
json114serde_json::Value / T: Deserializejson / typed_json::<T>()jsonjson
jsonb3802serde_json::Value / T: Deserializejsonb / typed_json::<T>()jsonjson
inet869std::net::IpAddrinetnetnet
cidr650babar::codec::Cidrcidrnetnet
macaddr829babar::codec::MacAddrmacaddrmacaddrmacaddr
macaddr8774babar::codec::MacAddr8macaddr8macaddrmacaddr
bit(n)1560babar::codec::BitStringbitbitsbits
varbit1562babar::codec::BitStringvarbitbitsbits
hstoreserver-assignedbabar::codec::Hstorehstorehstorehstore
citextserver-assignedStringcitextcitextcitext
tsvector3614babar::codec::TsVectortsvectortext_searchtext-search
tsquery3615babar::codec::TsQuerytsquerytext_searchtext-search
vectorserver-assignedbabar::codec::Vectorvectorpgvectorpgvector
geometry (PostGIS)server-assignedT: geo_types::*geometry::<T>()postgispostgis
geography (PostGIS)server-assignedT: geo_types::*geography::<T>()postgispostgis
range<T>range OIDbabar::codec::Range<T>range(C)rangerange
multirange<T>mr OIDbabar::codec::Multirange<T>multirange(C)multirangemultirange (implies range)

Composing codecs

Most type-system muscle lives in combinators, not new codec modules:

CombinatorWhat it does
nullable(C)Adds NULL → Option<T> handling. Required for any column that can be NULL.
array(C)One-dimensional Postgres arrays as Vec<T>.
range(C)Postgres ranges over T.
multirange(C)Postgres multiranges (Postgres 14+).
(C1, C2, …)A row tuple — Decoder<(A, B, …)> is auto-implemented for tuples of decoders.

For non-'static user types, write your own Encoder<A> / Decoder<A> (Chapter 10) — the codec module’s Encoder<UnitStruct> glue is small.

Next

For the cargo features that gate these codecs, see feature-flags.md. For the error variants codecs return on bad bytes, see errors.md.