From 1a9704eaad30b55d2a480f1c6a5159ab7841a232 Mon Sep 17 00:00:00 2001 From: Ari Seyhun Date: Tue, 12 Oct 2021 18:27:45 +0700 Subject: [PATCH] Add support for `Option>` into active model --- src/entity/active_model.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index 9ac92387..7e61b6f7 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -187,6 +187,24 @@ macro_rules! impl_into_active_value { $fn(self) } } + + impl IntoActiveValue> for Option<$ty> { + fn into_active_value(self) -> ActiveValue> { + match self { + Some(value) => Set(Some(value)), + None => Unset(None), + } + } + } + + impl IntoActiveValue> for Option> { + fn into_active_value(self) -> ActiveValue> { + match self { + Some(value) => Set(value), + None => Unset(None), + } + } + } }; } @@ -201,7 +219,6 @@ impl_into_active_value!(u32, Set); impl_into_active_value!(u64, Set); impl_into_active_value!(f32, Set); impl_into_active_value!(f64, Set); -impl_into_active_value!(&'static [u8], Set); impl_into_active_value!(&'static str, Set); impl_into_active_value!(String, Set); @@ -233,18 +250,6 @@ impl_into_active_value!(crate::prelude::Decimal, Set); #[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))] impl_into_active_value!(crate::prelude::Uuid, Set); -impl IntoActiveValue> for Option -where - V: Into + Nullable, -{ - fn into_active_value(self) -> ActiveValue> { - match self { - Some(value) => Set(Some(value)), - None => Unset(None), - } - } -} - impl ActiveValue where V: Into,