pub struct GraphTransaction {
pub label: Option<String>,
pub ops: Vec<GraphOp>,
}Expand description
A batch of edit operations that should be applied and undone as one unit.
Fields§
§label: Option<String>Optional human-readable label for history UI.
ops: Vec<GraphOp>Operations in order.
Implementations§
Source§impl GraphTransaction
impl GraphTransaction
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty transaction.
Examples found in repository?
32fn main() {
33 let node_id = NodeId::from_u128(2);
34 let mut graph = Graph::new(GraphId::from_u128(1));
35
36 let mut tx = GraphTransaction::new().with_label("add source node");
37 tx.push(GraphOp::AddNode {
38 id: node_id,
39 node: make_node("demo.source", 10.0, 20.0),
40 });
41 tx.apply_to(&mut graph).expect("transaction applies");
42
43 assert_eq!(graph.nodes().len(), 1);
44 assert_eq!(
45 graph.nodes()[&node_id].kind,
46 NodeKindKey::new("demo.source")
47 );
48}Sourcepub fn from_ops(ops: impl IntoIterator<Item = GraphOp>) -> Self
pub fn from_ops(ops: impl IntoIterator<Item = GraphOp>) -> Self
Creates an unlabeled transaction from ops.
Sourcepub fn from_parts(
label: Option<String>,
ops: impl IntoIterator<Item = GraphOp>,
) -> Self
pub fn from_parts( label: Option<String>, ops: impl IntoIterator<Item = GraphOp>, ) -> Self
Creates a transaction from metadata and ops.
Sourcepub fn diff(from: &Graph, to: &Graph) -> Self
pub fn diff(from: &Graph, to: &Graph) -> Self
Builds a deterministic transaction that transforms from into to.
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Sets a label.
Examples found in repository?
32fn main() {
33 let node_id = NodeId::from_u128(2);
34 let mut graph = Graph::new(GraphId::from_u128(1));
35
36 let mut tx = GraphTransaction::new().with_label("add source node");
37 tx.push(GraphOp::AddNode {
38 id: node_id,
39 node: make_node("demo.source", 10.0, 20.0),
40 });
41 tx.apply_to(&mut graph).expect("transaction applies");
42
43 assert_eq!(graph.nodes().len(), 1);
44 assert_eq!(
45 graph.nodes()[&node_id].kind,
46 NodeKindKey::new("demo.source")
47 );
48}Sourcepub fn with_optional_label(self, label: Option<String>) -> Self
pub fn with_optional_label(self, label: Option<String>) -> Self
Sets or clears the optional label.
Sourcepub fn with_ops(self, ops: impl IntoIterator<Item = GraphOp>) -> Self
pub fn with_ops(self, ops: impl IntoIterator<Item = GraphOp>) -> Self
Adds ops in order and returns this transaction.
Sourcepub fn map_ops(self, f: impl FnOnce(Vec<GraphOp>) -> Vec<GraphOp>) -> Self
pub fn map_ops(self, f: impl FnOnce(Vec<GraphOp>) -> Vec<GraphOp>) -> Self
Transforms this transaction’s ops while preserving metadata.
Sourcepub fn push(&mut self, op: GraphOp)
pub fn push(&mut self, op: GraphOp)
Pushes an op.
Examples found in repository?
32fn main() {
33 let node_id = NodeId::from_u128(2);
34 let mut graph = Graph::new(GraphId::from_u128(1));
35
36 let mut tx = GraphTransaction::new().with_label("add source node");
37 tx.push(GraphOp::AddNode {
38 id: node_id,
39 node: make_node("demo.source", 10.0, 20.0),
40 });
41 tx.apply_to(&mut graph).expect("transaction applies");
42
43 assert_eq!(graph.nodes().len(), 1);
44 assert_eq!(
45 graph.nodes()[&node_id].kind,
46 NodeKindKey::new("demo.source")
47 );
48}Sourcepub fn extend(&mut self, ops: impl IntoIterator<Item = GraphOp>)
pub fn extend(&mut self, ops: impl IntoIterator<Item = GraphOp>)
Extends this transaction with ops in order.
Sourcepub fn retain_ops(&mut self, f: impl FnMut(&GraphOp) -> bool)
pub fn retain_ops(&mut self, f: impl FnMut(&GraphOp) -> bool)
Retains ops that match f.
pub fn is_empty(&self) -> bool
Sourcepub fn into_parts(self) -> (Option<String>, Vec<GraphOp>)
pub fn into_parts(self) -> (Option<String>, Vec<GraphOp>)
Consumes this transaction and returns its metadata and ops.
Sourcepub fn apply_to(&self, graph: &mut Graph) -> Result<(), ApplyError>
pub fn apply_to(&self, graph: &mut Graph) -> Result<(), ApplyError>
Applies this transaction atomically to graph.
Examples found in repository?
32fn main() {
33 let node_id = NodeId::from_u128(2);
34 let mut graph = Graph::new(GraphId::from_u128(1));
35
36 let mut tx = GraphTransaction::new().with_label("add source node");
37 tx.push(GraphOp::AddNode {
38 id: node_id,
39 node: make_node("demo.source", 10.0, 20.0),
40 });
41 tx.apply_to(&mut graph).expect("transaction applies");
42
43 assert_eq!(graph.nodes().len(), 1);
44 assert_eq!(
45 graph.nodes()[&node_id].kind,
46 NodeKindKey::new("demo.source")
47 );
48}Source§impl GraphTransaction
impl GraphTransaction
Sourcepub fn footprint(&self) -> GraphMutationFootprint
pub fn footprint(&self) -> GraphMutationFootprint
Returns the graph-local ids touched by all operations in this transaction.
Sourcepub fn append_footprint(&self, footprint: &mut GraphMutationFootprint)
pub fn append_footprint(&self, footprint: &mut GraphMutationFootprint)
Appends this transaction’s touched ids to an existing footprint.
Trait Implementations§
Source§impl Clone for GraphTransaction
impl Clone for GraphTransaction
Source§fn clone(&self) -> GraphTransaction
fn clone(&self) -> GraphTransaction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more