Skip to content

Commit

Permalink
Remove Default bound from ActiveValue
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Jul 5, 2021
1 parent 53311d8 commit 732428f
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/entity/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ use std::fmt::Debug;
#[derive(Clone, Debug, Default)]
pub struct ActiveValue<V>
where
V: Into<Value> + Default,
V: Into<Value>,
{
value: V,
value: Option<V>,
state: ActiveValueState,
}

#[allow(non_snake_case)]
pub fn Set<V>(v: V) -> ActiveValue<V>
where
V: Into<Value> + Default,
V: Into<Value>,
{
ActiveValue::set(v)
}

#[allow(non_snake_case)]
pub fn Unset<V>(_: Option<bool>) -> ActiveValue<V>
where
V: Into<Value> + Default,
V: Into<Value>,
{
ActiveValue::unset()
}
Expand All @@ -45,7 +45,7 @@ impl Default for ActiveValueState {
#[doc(hidden)]
pub fn unchanged_active_value_not_intended_for_public_use<V>(value: V) -> ActiveValue<V>
where
V: Into<Value> + Default,
V: Into<Value>,
{
ActiveValue::unchanged(value)
}
Expand Down Expand Up @@ -111,11 +111,11 @@ where

impl<V> ActiveValue<V>
where
V: Into<Value> + Default,
V: Into<Value>,
{
pub fn set(value: V) -> Self {
Self {
value,
value: Some(value),
state: ActiveValueState::Set,
}
}
Expand All @@ -126,7 +126,7 @@ where

pub(crate) fn unchanged(value: V) -> Self {
Self {
value,
value: Some(value),
state: ActiveValueState::Unchanged,
}
}
Expand All @@ -137,7 +137,7 @@ where

pub fn unset() -> Self {
Self {
value: V::default(),
value: None,
state: ActiveValueState::Unset,
}
}
Expand All @@ -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<Value> {
Expand All @@ -170,19 +170,19 @@ where

impl<V> std::convert::AsRef<V> for ActiveValue<V>
where
V: Into<Value> + Default,
V: Into<Value>,
{
fn as_ref(&self) -> &V {
&self.value
self.value.as_ref().unwrap()
}
}

impl<V> PartialEq for ActiveValue<V>
where
V: Into<Value> + Default + std::cmp::PartialEq,
V: Into<Value> + std::cmp::PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.value == other.value
self.value.as_ref() == other.value.as_ref()
}
}

Expand Down

0 comments on commit 732428f

Please sign in to comment.