pub trait Assignable<Rhs: DataType = Self>: DataType { }Expand description
SQL types that accept a value of type Rhs: Self is the target (a
column or typed placeholder), Rhs the type of the value stored in it.
Used when binding Rust values to typed columns and placeholders, and for
INSERT ... SELECT. Assignment is stricter than Compatible and
one-directional: a target accepts only values it can hold without loss.
- Every dialect: a type accepts itself; the dialect’s
Anyaccepts every marker of that dialect; tuples are checked element by element. - SQLite:
RealacceptsInteger;NumericacceptsIntegerandReal. - PostgreSQL: wider integers accept narrower ones (
Int8acceptsInt4andInt2);Float4,Float8andNumericaccept every integer, andFloat8andNumericalso acceptFloat4(NumericalsoFloat8);Text,VarcharandCharaccept each other andEnum;TimestamptzacceptsTimestamp;TimetzacceptsTime;JsonbacceptsJson;CidracceptsInet. - MySQL: integers widen within range (an unsigned source fits a signed
target only when its whole range does), except that
MediumIntandMediumIntUnsignedalso acceptIntandIntUnsigned(Rust has no 24-bit integer; the server checks the range);Float,DoubleandDecimalaccept integers,DoubleacceptsFloat, andDecimalaccepts both;YearacceptsSmallIntUnsigned; text types accept each other,EnumandSet, andEnumandSetaccept text;Decimal,Jsonand the date/time types acceptText; binary types andBitaccept each other, andBitalso acceptsBooleanand unsigned integers.
Narrowing is rejected: an Int8 value cannot go into an Int4 column,
and a Text value cannot go into an Enum column. Placeholder
is not assignable; give it a type first.
§Examples
use drizzle_types::{Assignable, DataType};
use drizzle_types::postgres::types::{Float8, Int2, Int8, Jsonb, Json};
fn assignable<Target: Assignable<Value>, Value: DataType>() {}
assignable::<Int8, Int2>(); // an i16 fits in a bigint column
assignable::<Float8, Int8>(); // an integer fits in a double column
assignable::<Jsonb, Json>(); // a json value goes into a jsonb column§Type safety
ⓘ
use drizzle_types::{Assignable, DataType};
use drizzle_types::postgres::types::{Int4, Int8};
fn assignable<Target: Assignable<Value>, Value: DataType>() {}
assignable::<Int4, Int8>(); // an i64 does not fit in an integer columnDyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".