azure_functions/durable/
orchestration_output.rs1use crate::durable::IntoValue;
2use serde_json::Value;
3use std::iter::FromIterator;
4
5pub struct OrchestrationOutput(Value);
9
10impl<T> From<T> for OrchestrationOutput
11where
12 T: Into<Value>,
13{
14 fn from(t: T) -> Self {
15 OrchestrationOutput(t.into())
16 }
17}
18
19impl FromIterator<Value> for OrchestrationOutput {
20 fn from_iter<I>(iter: I) -> Self
21 where
22 I: IntoIterator<Item = Value>,
23 {
24 OrchestrationOutput(Value::from_iter(iter))
25 }
26}
27
28impl IntoValue for OrchestrationOutput {
29 fn into_value(self) -> Value {
30 self.0
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37 use serde_json::json;
38
39 #[test]
40 fn it_converts_from_json() {
41 let orchestration_output: OrchestrationOutput = json!({"foo": "bar"}).into();
42
43 let data: Value = orchestration_output.into_value();
44 assert_eq!(data, json!({"foo": "bar"}));
45 }
46
47 #[test]
48 fn it_converts_from_bool() {
49 let orchestration_output: OrchestrationOutput = true.into();
50
51 let data: Value = orchestration_output.into_value();
52 assert_eq!(data, json!(true));
53 }
54
55 #[test]
56 fn it_converts_from_string() {
57 let orchestration_output: OrchestrationOutput = "foo".into();
58
59 let data: Value = orchestration_output.into_value();
60 assert_eq!(data, json!("foo"));
61 }
62}