Merge pull request #223 from SeaQL/active-value-api

`ActiveValue::take()` & `ActiveValue::into_value()` without `unwrap()`
This commit is contained in:
Chris Tsang 2021-10-12 12:57:17 +08:00 committed by GitHub
commit edc2e6500d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);