diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index 96486ddaa..5ab7be191 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -7,16 +7,16 @@ use std::fmt::Debug; #[derive(Clone, Debug, Default)] pub struct ActiveValue where - V: Into + Default, + V: Into, { - value: V, + value: Option, state: ActiveValueState, } #[allow(non_snake_case)] pub fn Set(v: V) -> ActiveValue where - V: Into + Default, + V: Into, { ActiveValue::set(v) } @@ -24,7 +24,7 @@ where #[allow(non_snake_case)] pub fn Unset(_: Option) -> ActiveValue where - V: Into + Default, + V: Into, { ActiveValue::unset() } @@ -45,7 +45,7 @@ impl Default for ActiveValueState { #[doc(hidden)] pub fn unchanged_active_value_not_intended_for_public_use(value: V) -> ActiveValue where - V: Into + Default, + V: Into, { ActiveValue::unchanged(value) } @@ -111,11 +111,11 @@ where impl ActiveValue where - V: Into + Default, + V: Into, { pub fn set(value: V) -> Self { Self { - value, + value: Some(value), state: ActiveValueState::Set, } } @@ -126,7 +126,7 @@ where pub(crate) fn unchanged(value: V) -> Self { Self { - value, + value: Some(value), state: ActiveValueState::Unchanged, } } @@ -137,7 +137,7 @@ where pub fn unset() -> Self { Self { - value: V::default(), + value: None, state: ActiveValueState::Unset, } } @@ -148,15 +148,15 @@ where pub fn take(&mut self) -> V { self.state = ActiveValueState::Unset; - std::mem::take(&mut self.value) + self.value.take().unwrap() } pub fn unwrap(self) -> V { - self.value + self.value.unwrap() } pub fn into_value(self) -> Value { - self.value.into() + self.value.unwrap().into() } pub fn into_wrapped_value(self) -> ActiveValue { @@ -170,19 +170,19 @@ where impl std::convert::AsRef for ActiveValue where - V: Into + Default, + V: Into, { fn as_ref(&self) -> &V { - &self.value + self.value.as_ref().unwrap() } } impl PartialEq for ActiveValue where - V: Into + Default + std::cmp::PartialEq, + V: Into + std::cmp::PartialEq, { fn eq(&self, other: &Self) -> bool { - self.value == other.value + self.value.as_ref() == other.value.as_ref() } }