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?
examples/build_graph.rs (line 36)
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!(graph.nodes[&node_id].kind, NodeKindKey::new("demo.source"));
45}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?
examples/build_graph.rs (line 36)
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!(graph.nodes[&node_id].kind, NodeKindKey::new("demo.source"));
45}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?
examples/build_graph.rs (lines 37-40)
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!(graph.nodes[&node_id].kind, NodeKindKey::new("demo.source"));
45}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?
examples/build_graph.rs (line 41)
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!(graph.nodes[&node_id].kind, NodeKindKey::new("demo.source"));
45}Trait Implementations§
Source§impl Clone for GraphTransaction
impl Clone for GraphTransaction
Source§fn clone(&self) -> GraphTransaction
fn clone(&self) -> GraphTransaction
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 Debug for GraphTransaction
impl Debug for GraphTransaction
Source§impl Default for GraphTransaction
impl Default for GraphTransaction
Source§fn default() -> GraphTransaction
fn default() -> GraphTransaction
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for GraphTransaction
impl<'de> Deserialize<'de> for GraphTransaction
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for GraphTransaction
impl RefUnwindSafe for GraphTransaction
impl Send for GraphTransaction
impl Sync for GraphTransaction
impl Unpin for GraphTransaction
impl UnsafeUnpin for GraphTransaction
impl UnwindSafe for GraphTransaction
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