temporalio_common_wasm/
workflow_execution.rs1use crate::protos::temporal::api::common::v1::WorkflowExecution as ProtoWorkflowExecution;
2
3#[derive(Clone, Debug, Default, PartialEq)]
5#[non_exhaustive]
6pub struct WorkflowExecution {
7 raw: ProtoWorkflowExecution,
8}
9
10#[bon::bon]
11impl WorkflowExecution {
12 #[builder(on(String, into), state_mod(vis = "pub"))]
14 pub fn new(workflow_id: String, run_id: String) -> Self {
15 let mut execution = Self::default();
16 execution.set_workflow_id(workflow_id).set_run_id(run_id);
17 execution
18 }
19
20 pub fn workflow_id(&self) -> &str {
22 &self.raw.workflow_id
23 }
24
25 pub fn set_workflow_id(&mut self, workflow_id: impl Into<String>) -> &mut Self {
27 self.raw.workflow_id = workflow_id.into();
28 self
29 }
30
31 pub fn run_id(&self) -> &str {
33 &self.raw.run_id
34 }
35
36 pub fn set_run_id(&mut self, run_id: impl Into<String>) -> &mut Self {
38 self.raw.run_id = run_id.into();
39 self
40 }
41
42 pub fn raw(&self) -> &ProtoWorkflowExecution {
44 &self.raw
45 }
46
47 pub fn into_raw(self) -> ProtoWorkflowExecution {
49 self.raw
50 }
51}
52
53impl From<ProtoWorkflowExecution> for WorkflowExecution {
54 fn from(value: ProtoWorkflowExecution) -> Self {
55 Self { raw: value }
56 }
57}
58
59impl From<WorkflowExecution> for ProtoWorkflowExecution {
60 fn from(value: WorkflowExecution) -> Self {
61 value.raw
62 }
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn builder_and_proto_round_trip() {
71 let execution = WorkflowExecution::builder()
72 .workflow_id("workflow-id")
73 .run_id("run-id")
74 .build();
75
76 assert_eq!(execution.workflow_id(), "workflow-id");
77 assert_eq!(execution.run_id(), "run-id");
78 assert_eq!(execution.raw().workflow_id, "workflow-id");
79 assert_eq!(execution.raw().run_id, "run-id");
80
81 assert_eq!(
82 WorkflowExecution::from(ProtoWorkflowExecution::from(execution.clone())),
83 execution
84 );
85 }
86
87 #[test]
88 fn setters_update_raw_proto() {
89 let mut execution = WorkflowExecution::default();
90 execution
91 .set_workflow_id("workflow-id")
92 .set_run_id("run-id");
93
94 assert_eq!(execution.workflow_id(), "workflow-id");
95 assert_eq!(execution.run_id(), "run-id");
96 assert_eq!(execution.raw().workflow_id, "workflow-id");
97 assert_eq!(execution.raw().run_id, "run-id");
98 }
99}