pub enum ActiveValue<T> {
Set(T),
Unchanged,
NotSet,
}Expand description
字段值的三态表示
类比 SeaORM 的 ActiveValue / Rails 的 ActiveModel::Attribute:
| 变体 | 含义 | UPDATE 行为 |
|---|---|---|
Set(v) | 用户显式设置了新值 | 包含在 SET 子句 |
Unchanged | 字段存在但未被修改 | 不包含在 SET 子句 |
NotSet | 字段尚未被赋值(新建模型默认状态) | 不包含在 SET 子句 |
§示例
use sz_orm_core::active_model::ActiveValue;
use sz_orm_core::Value;
// 设置一个字段
let av: ActiveValue<Value> = ActiveValue::Set(Value::String("Alice".into()));
assert!(av.is_set());
// 从任意 Into<Value> 类型自动转换
let av: ActiveValue<Value> = "hello".into();
assert_eq!(av.into_value(), Some(Value::String("hello".into())));
// NotSet 是默认值
let av: ActiveValue<Value> = ActiveValue::default();
assert!(av.is_not_set());Variants§
Implementations§
Source§impl<T> ActiveValue<T>
impl<T> ActiveValue<T>
Trait Implementations§
Source§impl<T: Clone> Clone for ActiveValue<T>
impl<T: Clone> Clone for ActiveValue<T>
Source§fn clone(&self) -> ActiveValue<T>
fn clone(&self) -> ActiveValue<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for ActiveValue<T>
impl<T: Debug> Debug for ActiveValue<T>
Source§impl<T> Default for ActiveValue<T>
impl<T> Default for ActiveValue<T>
Source§fn default() -> ActiveValue<T>
fn default() -> ActiveValue<T>
Returns the “default value” for a type. Read more
Source§impl<T: Into<Value>> From<T> for ActiveValue<Value>
从任意 Into<Value> 类型自动转换为 ActiveValue<Value>
impl<T: Into<Value>> From<T> for ActiveValue<Value>
从任意 Into<Value> 类型自动转换为 ActiveValue<Value>
这使得 active.set("name", "Alice") 可以自动将 "Alice" 转为 ActiveValue::Set(Value::String(...))。
Source§impl<T: PartialEq> PartialEq for ActiveValue<T>
impl<T: PartialEq> PartialEq for ActiveValue<T>
impl<T: PartialEq> StructuralPartialEq for ActiveValue<T>
Auto Trait Implementations§
impl<T> Freeze for ActiveValue<T>where
T: Freeze,
impl<T> RefUnwindSafe for ActiveValue<T>where
T: RefUnwindSafe,
impl<T> Send for ActiveValue<T>where
T: Send,
impl<T> Sync for ActiveValue<T>where
T: Sync,
impl<T> Unpin for ActiveValue<T>where
T: Unpin,
impl<T> UnsafeUnpin for ActiveValue<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ActiveValue<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more