Struct Draft

Source
pub struct Draft {
    pub base: Arc<NodePool>,
    pub inner: NodePoolInner,
    pub patches: Vector<Patch>,
    pub current_path: Vector<String>,
    pub skip_record: bool,
    pub begin: bool,
}
Expand description

草稿修改上下文,用于安全地修改节点池

跟踪以下信息:

  • 基础版本节点池
  • 当前修改的中间状态
  • 生成的修改补丁
  • 当前操作路径(用于嵌套数据结构)

Fields§

§base: Arc<NodePool>§inner: NodePoolInner§patches: Vector<Patch>§current_path: Vector<String>§skip_record: bool§begin: bool

Implementations§

Source§

impl Draft

Source

pub fn new(base: Arc<NodePool>) -> Self

创建基于现有节点池的草稿

§参数
  • base - 基础版本节点池的引用
Source

pub fn enter_map(&mut self, key: &str) -> &mut Self

进入嵌套路径(用于记录结构化修改)

§参数
  • key - Map 类型的字段名称
§示例
draft.enter_map("content").enter_list(0);
Source

pub fn enter_list(&mut self, index: usize) -> &mut Self

进入嵌套路径(List类型索引)

Source

pub fn exit(&mut self) -> &mut Self

退出当前路径层级

Source

pub fn update_attr( &mut self, id: &NodeId, new_values: HashMap<String, Value>, ) -> Result<(), PoolError>

提交属性修改并记录补丁

§参数
  • id - 目标节点ID
  • new_values - 新属性集合
§错误

当节点不存在时返回 PoolError::NodeNotFound

Source

pub fn remove_mark(&mut self, id: &NodeId, mark: Mark) -> Result<(), PoolError>

从节点中移除指定标记

§参数
  • id - 目标节点ID
  • mark - 要移除的标记
§错误

当节点不存在时返回 PoolError::NodeNotFound

Source

pub fn add_mark(&mut self, id: &NodeId, mark: Mark) -> Result<(), PoolError>

为节点添加标记

§参数
  • id - 目标节点ID
  • mark - 要添加的标记
§错误

当节点不存在时返回 PoolError::NodeNotFound

Source

pub fn sort_children<F: FnMut(&(String, &Arc<Node>), &(String, &Arc<Node>)) -> Ordering>( &mut self, parent_id: &NodeId, compare: F, ) -> Result<(), PoolError>

Source

pub fn add_node( &mut self, parent_id: &NodeId, node: Node, ) -> Result<(), PoolError>

添加子节点

Source

pub fn replace_node( &mut self, node_id: NodeId, new_node: Arc<Node>, ) -> Result<(), PoolError>

Source

pub fn move_node( &mut self, source_parent_id: &NodeId, target_parent_id: &NodeId, node_id: &NodeId, position: Option<usize>, ) -> Result<(), PoolError>

移动节点

Source

pub fn get_node(&self, id: &NodeId) -> Option<&Arc<Node>>

Source

pub fn children(&self, parent_id: &NodeId) -> Option<&Vector<NodeId>>

Source

pub fn remove_node( &mut self, parent_id: &NodeId, nodes: Vec<NodeId>, ) -> Result<(), PoolError>

移除子节点

§参数
  • parent_id - 父节点ID
  • nodes - 要移除的子节点ID列表
§错误

当父节点不存在时返回 PoolError::ParentNotFound

Source

pub fn apply_patches(&mut self, patches: &Vec<Patch>) -> Result<(), PoolError>

应用补丁集合并更新节点池

§参数
  • patches - 要应用的补丁集合
§注意

应用过程中会临时禁用补丁记录

Source

pub fn reverse_patches(&mut self, patches: Vec<Patch>) -> Result<(), PoolError>

翻转补丁集合并应用到节点池

Source

pub fn commit(&self) -> StepResult

提交修改,生成新 NodePool 和补丁列表

Trait Implementations§

Source§

impl Clone for Draft

Source§

fn clone(&self) -> Draft

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 Draft

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Draft

§

impl RefUnwindSafe for Draft

§

impl Send for Draft

§

impl Sync for Draft

§

impl Unpin for Draft

§

impl UnwindSafe for Draft

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more