ActiveValue::take() & ActiveValue::into_value() without unwrap()

This commit is contained in:
Billy Chan 2021-10-04 12:17:31 +08:00
parent 700a0206e7
commit 35b8eb9a4d
No known key found for this signature in database
GPG Key ID: A2D690CAC7DF3CC7
2 changed files with 7 additions and 7 deletions

View File

@ -209,23 +209,23 @@ where
matches!(self.state, ActiveValueState::Unset) matches!(self.state, ActiveValueState::Unset)
} }
pub fn take(&mut self) -> V { pub fn take(&mut self) -> Option<V> {
self.state = ActiveValueState::Unset; self.state = ActiveValueState::Unset;
self.value.take().unwrap() self.value.take()
} }
pub fn unwrap(self) -> V { pub fn unwrap(self) -> V {
self.value.unwrap() self.value.unwrap()
} }
pub fn into_value(self) -> Value { pub fn into_value(self) -> Option<Value> {
self.value.unwrap().into() self.value.map(Into::into)
} }
pub fn into_wrapped_value(self) -> ActiveValue<Value> { pub fn into_wrapped_value(self) -> ActiveValue<Value> {
match self.state { match self.state {
ActiveValueState::Set => ActiveValue::set(self.into_value()), ActiveValueState::Set => ActiveValue::set(self.into_value().unwrap()),
ActiveValueState::Unchanged => ActiveValue::unchanged(self.into_value()), ActiveValueState::Unchanged => ActiveValue::unchanged(self.into_value().unwrap()),
ActiveValueState::Unset => ActiveValue::unset(), ActiveValueState::Unset => ActiveValue::unset(),
} }
} }

View File

@ -120,7 +120,7 @@ where
} }
if av_has_val { if av_has_val {
columns.push(col); columns.push(col);
values.push(av.into_value()); values.push(av.into_value().unwrap());
} }
} }
self.query.columns(columns); self.query.columns(columns);