Struct Transaction

Source
pub struct Transaction {
    pub meta: HashMap<String, Arc<dyn Any>>,
    pub id: u64,
    pub steps: Vector<Arc<dyn Step>>,
    pub patches: Vector<Vec<Patch>>,
    pub doc: Arc<NodePool>,
    pub draft: Draft,
    pub schema: Arc<Schema>,
}
Expand description

事务结构体,用于管理文档的修改操作

Fields§

§meta: HashMap<String, Arc<dyn Any>>

存储元数据的哈希表,支持任意类型数据

§id: u64

事务的时间戳

§steps: Vector<Arc<dyn Step>>

存储所有操作步骤

§patches: Vector<Vec<Patch>>

存储每个步骤对应的补丁列表

§doc: Arc<NodePool>

当前文档状态

§draft: Draft

文档的草稿状态,用于临时修改

§schema: Arc<Schema>

文档的模式定义

Implementations§

Source§

impl Transaction

Source

pub async fn transaction(&mut self, call_back: Arc<dyn Command>)

执行一个事务操作 call_back: 要执行的命令

Source

pub fn new(state: &State) -> Self

创建新的事务实例 state: 当前状态对象 返回: Transaction 实例

Source

pub fn doc(&self) -> Arc<NodePool>

获取当前文档状态

Source

pub fn as_concrete(step: &Arc<dyn Step>) -> ConcreteStep

将步骤转换为具体步骤

Source

pub fn set_node_attribute( &mut self, id: String, values: HashMap<String, String>, )

设置节点属性 id: 节点ID values: 属性键值对

Source

pub fn add_node(&mut self, parent_id: String, node: Node)

添加新节点 parent_id: 父节点ID node: 要添加的节点

Source

pub fn set_time(&mut self, id: u64) -> &mut Self

设置事务时间戳

Source

pub fn set_meta<K, T: Any>(&mut self, key: K, value: T) -> &mut Self
where K: Into<String>,

设置元数据 key: 键 value: 值(支持任意类型)

Source

pub fn get_meta<T: 'static, K>(&self, key: K) -> Option<&T>
where K: Into<String>,

获取元数据 key: 键 返回: Option<&T>,如果存在且类型匹配则返回Some,否则返回None

Trait Implementations§

Source§

impl Clone for Transaction

Source§

fn clone(&self) -> Transaction

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Transform for Transaction

Source§

fn step(&mut self, step: Arc<dyn Step>) -> Result<(), TransformError>

执行一个修改步骤 step: 要执行的步骤 返回: Result,表示执行成功或失败

Source§

fn doc_changed(&self) -> bool

检查文档是否被修改

Source§

fn add_step(&mut self, step: Arc<dyn Step>, result: StepResult)

添加一个步骤及其结果到事务中

Source§

impl Send for Transaction

Source§

impl Sync for Transaction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.