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

Data Type

The library intentionally rejects conversions that could silently lose data. For example, reading a BIGINT column as i8 will return an error rather than truncating the value. This ensures data integrity and makes bugs easier to catch.

Widening conversions (e.g., reading TINYINT as i64) are allowed.

Parameter Types (Rust to MySQL)

Rust TypeMySQL TypeNotes
boolTINYINTEncoded as 0 or 1
i8TINYINT
i16SMALLINT
i32INT
i64BIGINT
u8TINYINT UNSIGNED
u16SMALLINT UNSIGNED
u32INT UNSIGNED
u64BIGINT UNSIGNED
f32FLOAT
f64DOUBLE
&strVARCHAR
StringVARCHAR
&[u8]BLOB
Vec<u8>BLOB
Option<T>Same as TNone encodes as NULL

Result Types (MySQL to Rust)

Signed and unsigned types are strictly separated. You cannot decode a signed column (e.g., TINYINT) to an unsigned Rust type (e.g., u8), or vice versa.

MySQL TypeRust Types
TINYINTi8, i16, i32, i64, bool
SMALLINTi16, i32, i64
MEDIUMINT, INTi32, i64
BIGINTi64
TINYINT UNSIGNEDu8, u16, u32, u64, bool
SMALLINT UNSIGNEDu16, u32, u64
MEDIUMINT UNSIGNED, INT UNSIGNEDu32, u64
BIGINT UNSIGNEDu64
FLOATf32, f64
DOUBLEf64
VARCHAR, CHAR, TEXT, etc.&str, String
BLOB, BINARY, VARBINARY, etc.&[u8], Vec<u8>
NULLOption<T>

Date and Time Types

Date/time types are exposed through the Value enum:

MySQL TypeValue Variants
DATEDate0, Date4
DATETIME, TIMESTAMPDatetime0, Datetime4, Datetime7, Datetime11
TIMETime0, Time8, Time12

The numeric suffix indicates the wire format byte length.

DECIMAL Type

DECIMAL and NUMERIC columns are returned as Value::Byte containing the string representation.

Feature-Gated Types

Additional type support is available through feature flags.

with-uuid (uuid crate)

Rust TypeMySQL TypeNotes
uuid::UuidVARCHAR(36)Encoded as hyphenated string
MySQL TypeRust TypeNotes
VARCHAR, CHARuuid::UuidParsed from hyphenated string
BINARY(16)uuid::UuidParsed from 16 bytes

with-chrono (chrono crate)

Rust TypeMySQL Type
chrono::NaiveDateDATE
chrono::NaiveTimeTIME
chrono::NaiveDateTimeDATETIME
MySQL TypeRust TypeNotes
DATEchrono::NaiveDateZero dates (0000-00-00) return an error
TIMEchrono::NaiveTimeNegative times or times with days return an error
DATETIME, TIMESTAMPchrono::NaiveDateTimeZero datetimes return an error

with-time (time crate)

Rust TypeMySQL Type
time::DateDATE
time::TimeTIME
time::PrimitiveDateTimeDATETIME
MySQL TypeRust TypeNotes
DATEtime::DateZero dates return an error
TIMEtime::TimeNegative times or times with days return an error
DATETIME, TIMESTAMPtime::PrimitiveDateTimeZero datetimes return an error

with-rust-decimal (rust_decimal crate)

Rust TypeMySQL Type
rust_decimal::DecimalDECIMAL
MySQL TypeRust TypeNotes
DECIMALrust_decimal::Decimal96-bit precision, not arbitrary like MySQL