pub trait IntoPrimaryKey<T: super::Model> {
fn into_primary_key(self) -> T::PrimaryKey;
}
impl<T: super::Model> IntoPrimaryKey<T> for &T {
fn into_primary_key(self) -> T::PrimaryKey {
self.primary_key().expect(
"Model instance passed to new() must have a primary key set. \
Ensure the model was created with new() or loaded from database.",
)
}
}
impl<T: super::Model<PrimaryKey = uuid::Uuid>> IntoPrimaryKey<T> for uuid::Uuid {
fn into_primary_key(self) -> T::PrimaryKey {
self
}
}
impl<T: super::Model<PrimaryKey = i32>> IntoPrimaryKey<T> for i32 {
fn into_primary_key(self) -> T::PrimaryKey {
self
}
}
impl<T: super::Model<PrimaryKey = i64>> IntoPrimaryKey<T> for i64 {
fn into_primary_key(self) -> T::PrimaryKey {
self
}
}
impl<T: super::Model<PrimaryKey = uuid::Uuid>> IntoPrimaryKey<T> for Option<uuid::Uuid> {
fn into_primary_key(self) -> T::PrimaryKey {
self.expect("Primary key value must be provided")
}
}
impl<T: super::Model<PrimaryKey = i32>> IntoPrimaryKey<T> for Option<i32> {
fn into_primary_key(self) -> T::PrimaryKey {
self.expect("Primary key value must be provided")
}
}
impl<T: super::Model<PrimaryKey = i64>> IntoPrimaryKey<T> for Option<i64> {
fn into_primary_key(self) -> T::PrimaryKey {
self.expect("Primary key value must be provided")
}
}