From 35b8eb9a4df9c284f03625c707c677f978b881fb Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 4 Oct 2021 12:17:31 +0800 Subject: [PATCH] `ActiveValue::take()` & `ActiveValue::into_value()` without `unwrap()` --- src/entity/active_model.rs | 12 ++++++------ src/query/insert.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index cfcb0bbdf..6f4b86f69 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -209,23 +209,23 @@ where matches!(self.state, ActiveValueState::Unset) } - pub fn take(&mut self) -> V { + pub fn take(&mut self) -> Option { self.state = ActiveValueState::Unset; - self.value.take().unwrap() + self.value.take() } pub fn unwrap(self) -> V { self.value.unwrap() } - pub fn into_value(self) -> Value { - self.value.unwrap().into() + pub fn into_value(self) -> Option { + self.value.map(Into::into) } pub fn into_wrapped_value(self) -> ActiveValue { match self.state { - ActiveValueState::Set => ActiveValue::set(self.into_value()), - ActiveValueState::Unchanged => ActiveValue::unchanged(self.into_value()), + ActiveValueState::Set => ActiveValue::set(self.into_value().unwrap()), + ActiveValueState::Unchanged => ActiveValue::unchanged(self.into_value().unwrap()), ActiveValueState::Unset => ActiveValue::unset(), } } diff --git a/src/query/insert.rs b/src/query/insert.rs index a65071e18..f2d60dc8e 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -120,7 +120,7 @@ where } if av_has_val { columns.push(col); - values.push(av.into_value()); + values.push(av.into_value().unwrap()); } } self.query.columns(columns);