pub trait DatabaseField: FromDbValue + ToDbFieldValue {
const TYPE: ColumnType;
const NULLABLE: bool = false;
}db only.Expand description
A trait denoting that some type can be used as a field in a database.
Required Associated Constants§
Sourceconst TYPE: ColumnType
const TYPE: ColumnType
The type of the column in the database as one of the variants of
the ColumnType enum.
§Changing the column type after initial implementation
Note that this should never be changed after the type is implemented. The migration generator is unable to detect a change in the column type and will not generate a migration for it. If the column type needs to be changed, a manual migration should be written, or a new type should be created.
This is especially important for types that are stored as fixed-length
strings in the database, as the migration generator cannot detect a
change in the string length. For this reason, it’s recommended to use
the LimitedString type for fixed-length strings (which uses const
generics, so each change in the length will be a new type) instead of
a custom type with a fixed length.
Provided Associated Constants§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.