reactive_graph_reactive_model_impl/flows/
reactive_flow.rs1use crate::ReactiveEntity;
2use crate::ReactiveRelation;
3use reactive_graph_behaviour_model_api::BehaviourTypeId;
4use reactive_graph_behaviour_model_api::BehaviourTypeIds;
5use reactive_graph_behaviour_model_api::BehaviourTypesContainer;
6use reactive_graph_graph::Component;
7use reactive_graph_graph::ComponentContainer;
8use reactive_graph_graph::ComponentTypeId;
9use reactive_graph_graph::ComponentTypeIds;
10use reactive_graph_graph::CreateFlowInstanceError;
11use reactive_graph_graph::EntityInstance;
12use reactive_graph_graph::EntityTypeId;
13use reactive_graph_graph::FlowInstance;
14use reactive_graph_graph::Mutability;
15use reactive_graph_graph::Namespace;
16use reactive_graph_graph::NamespaceSegment;
17use reactive_graph_graph::NamespacedType;
18use reactive_graph_graph::NamespacedTypeGetter;
19use reactive_graph_graph::PropertyInstanceGetter;
20use reactive_graph_graph::PropertyInstanceSetter;
21use reactive_graph_graph::PropertyType;
22use reactive_graph_graph::RelationInstance;
23use reactive_graph_graph::RelationInstanceId;
24use reactive_graph_graph::TypeDefinition;
25use reactive_graph_graph::TypeDefinitionGetter;
26use reactive_graph_graph::TypeIdType;
27use reactive_graph_graph::instances::named::NamedInstanceContainer;
28use reactive_graph_reactive_model_api::ReactiveFlowConstructionError;
29use reactive_graph_reactive_model_api::ReactiveInstance;
30use reactive_graph_reactive_model_api::ReactiveInstanceUnidentifiable;
31use reactive_graph_reactive_model_api::ReactivePropertyContainer;
32use serde_json::Map;
33use serde_json::Value;
34use std::collections::HashMap;
35use std::fmt;
36use std::fmt::Display;
37use std::fmt::Formatter;
38use std::ops::Deref;
39use std::sync::Arc;
40use std::sync::RwLock;
41use uuid::Uuid;
42
43pub struct ReactiveFlowInstance {
44 pub id: Uuid,
46
47 pub ty: EntityTypeId,
49
50 pub name: String,
52
53 pub description: String,
55
56 pub entity_instances: RwLock<HashMap<Uuid, ReactiveEntity>>,
59
60 pub relation_instances: RwLock<HashMap<RelationInstanceId, ReactiveRelation>>,
63
64 pub entities_added: RwLock<Vec<Uuid>>,
66
67 pub entities_removed: RwLock<Vec<Uuid>>,
69
70 pub relations_added: RwLock<Vec<RelationInstanceId>>,
72
73 pub relations_removed: RwLock<Vec<RelationInstanceId>>,
75}
76
77impl ReactiveFlowInstance {
78 pub fn new(wrapper_entity_instance: ReactiveEntity) -> Self {
79 let mut entity_instances = HashMap::new();
80 entity_instances.insert(wrapper_entity_instance.id, wrapper_entity_instance.clone());
81 ReactiveFlowInstance {
82 id: wrapper_entity_instance.id,
83 ty: wrapper_entity_instance.ty.clone(),
84 name: String::new(),
85 description: String::new(),
86 entity_instances: RwLock::new(entity_instances),
87 relation_instances: RwLock::new(HashMap::new()),
88 entities_added: RwLock::new(Vec::new()),
89 entities_removed: RwLock::new(Vec::new()),
90 relations_added: RwLock::new(Vec::new()),
91 relations_removed: RwLock::new(Vec::new()),
92 }
93 }
94
95 pub fn has_entity(&self, entity_instance: ReactiveEntity) -> bool {
96 self.entity_instances.read().unwrap().contains_key(&entity_instance.id)
97 }
98
99 pub fn has_entity_by_id(&self, id: Uuid) -> bool {
100 self.entity_instances.read().unwrap().contains_key(&id)
101 }
102
103 pub fn get_entity(&self, id: Uuid) -> Option<ReactiveEntity> {
104 let reader = self.entity_instances.read().unwrap();
105 reader.get(&id).cloned()
106 }
107
108 pub fn get_wrapper_entity_instance(&self) -> Option<ReactiveEntity> {
109 self.get_entity(self.id)
110 }
111
112 pub fn add_entity(&self, entity_instance: ReactiveEntity) {
113 let id = entity_instance.id;
114 if !self.has_entity_by_id(id) {
115 self.entity_instances.write().unwrap().insert(id, entity_instance);
116 self.entities_added.write().unwrap().push(id);
117 }
119 }
120
121 pub fn remove_entity(&self, id: Uuid) {
122 self.entity_instances.write().unwrap().remove(&id);
123 self.entities_removed.write().unwrap().push(id);
124 }
125
126 pub fn has_relation(&self, relation_instance: ReactiveRelation) -> bool {
127 self.relation_instances.read().unwrap().contains_key(&relation_instance.id())
128 }
129
130 pub fn has_relation_by_key(&self, relation_instance_id: &RelationInstanceId) -> bool {
131 self.relation_instances.read().unwrap().contains_key(relation_instance_id)
132 }
133
134 pub fn get_relation(&self, relation_instance_id: &RelationInstanceId) -> Option<ReactiveRelation> {
135 let reader = self.relation_instances.read().unwrap();
136 reader.get(relation_instance_id).cloned()
137 }
138
139 pub fn add_relation(&self, relation_instance: ReactiveRelation) {
140 let id = relation_instance.id();
141 if !self.has_relation_by_key(&id) {
142 self.relation_instances.write().unwrap().insert(id.clone(), relation_instance);
143 self.relations_added.write().unwrap().push(id);
144 }
145 }
146
147 pub fn remove_relation(&self, relation_instance_id: &RelationInstanceId) {
148 self.relation_instances.write().unwrap().remove(relation_instance_id);
149 self.relations_removed.write().unwrap().push(relation_instance_id.clone());
150 }
151
152 pub fn tick(&self) {
153 let reader = self.entity_instances.read().unwrap();
154 for (_, entity_instance) in reader.iter() {
155 entity_instance.tick();
156 }
157 }
158}
159
160impl From<ReactiveEntity> for ReactiveFlowInstance {
161 fn from(wrapper_entity_instance: ReactiveEntity) -> Self {
162 ReactiveFlowInstance::new(wrapper_entity_instance)
163 }
164}
165
166impl TryFrom<FlowInstance> for ReactiveFlowInstance {
167 type Error = ReactiveFlowConstructionError;
168
169 fn try_from(flow_instance: FlowInstance) -> Result<Self, ReactiveFlowConstructionError> {
170 let flow_id = flow_instance.id;
171 let mut entity_instances = HashMap::new();
172 let mut wrapper = None;
173 for (id, entity_instance) in flow_instance.entity_instances {
174 let reactive_entity = ReactiveEntity::from(entity_instance);
175 entity_instances.insert(id, reactive_entity.clone());
176 if id == flow_id {
177 wrapper = Some(reactive_entity.clone());
178 }
179 }
180 if wrapper.is_none() {
181 return Err(ReactiveFlowConstructionError::MissingWrapperInstance);
182 }
183 let mut relation_instances = HashMap::new();
184 for (id, relation_instance) in flow_instance.relation_instances {
185 let outbound = entity_instances.get(&relation_instance.outbound_id);
187 if outbound.is_none() {
188 return Err(ReactiveFlowConstructionError::MissingOutboundEntityInstance(relation_instance.outbound_id));
190 }
191 let inbound = entity_instances.get(&relation_instance.inbound_id);
192 if inbound.is_none() {
193 return Err(ReactiveFlowConstructionError::MissingInboundEntityInstance(relation_instance.inbound_id));
195 }
196 let outbound = outbound.unwrap().clone();
197 let inbound = inbound.unwrap().clone();
198 let reactive_relation = ReactiveRelation::new_from_instance(outbound, inbound, relation_instance.clone());
199 relation_instances.insert(id, reactive_relation);
200 }
201 Ok(ReactiveFlowInstance {
202 id: flow_id,
203 ty: flow_instance.ty,
204 name: flow_instance.name.clone(),
205 description: flow_instance.description.clone(),
206 entity_instances: RwLock::new(entity_instances),
207 relation_instances: RwLock::new(relation_instances),
208 entities_added: RwLock::new(Vec::new()),
210 entities_removed: RwLock::new(Vec::new()),
211 relations_added: RwLock::new(Vec::new()),
212 relations_removed: RwLock::new(Vec::new()),
213 })
214 }
215}
216
217impl PropertyInstanceGetter for ReactiveFlowInstance {
218 fn get(&self, property_name: &str) -> Option<Value> {
219 self.get_entity(self.id).and_then(|e| e.properties.get(property_name).map(|p| p.get()))
220 }
221
222 fn as_bool(&self, property_name: &str) -> Option<bool> {
223 self.get_entity(self.id).and_then(|e| e.properties.get(property_name).and_then(|p| p.as_bool()))
224 }
225
226 fn as_u64(&self, property_name: &str) -> Option<u64> {
227 self.get_entity(self.id).and_then(|e| e.properties.get(property_name).and_then(|p| p.as_u64()))
228 }
229
230 fn as_i64(&self, property_name: &str) -> Option<i64> {
231 self.get_entity(self.id).and_then(|e| e.properties.get(property_name).and_then(|p| p.as_i64()))
232 }
233
234 fn as_f64(&self, property_name: &str) -> Option<f64> {
235 self.get_entity(self.id).and_then(|e| e.properties.get(property_name).and_then(|p| p.as_f64()))
236 }
237
238 fn as_string(&self, property_name: &str) -> Option<String> {
239 self.get_entity(self.id)
240 .and_then(|e| e.properties.get(property_name).and_then(|p| p.as_string()))
241 }
242
243 fn as_array(&self, property_name: &str) -> Option<Vec<Value>> {
244 self.get_entity(self.id)
245 .and_then(|e| e.properties.get(property_name).and_then(|p| p.as_array()))
246 }
247
248 fn as_object(&self, property_name: &str) -> Option<Map<String, Value>> {
249 self.get_entity(self.id)
250 .and_then(|e| e.properties.get(property_name).and_then(|p| p.as_object()))
251 }
252}
253
254impl PropertyInstanceSetter for ReactiveFlowInstance {
255 fn set_checked(&self, property_name: &str, value: Value) {
256 if let Some(instance) = self.get_entity(self.id) {
257 if let Some(instance) = instance.properties.get(property_name) {
258 instance.set_checked(value);
259 }
260 }
261 }
262
263 fn set(&self, property_name: &str, value: Value) {
264 if let Some(instance) = self.get_entity(self.id) {
265 if let Some(instance) = instance.properties.get(property_name) {
266 instance.set(value);
267 }
268 }
269 }
270
271 fn set_no_propagate_checked(&self, property_name: &str, value: Value) {
272 if let Some(instance) = self.get_entity(self.id) {
273 if let Some(instance) = instance.properties.get(property_name) {
274 instance.set_no_propagate_checked(value);
275 }
276 }
277 }
278
279 fn set_no_propagate(&self, property_name: &str, value: Value) {
280 if let Some(instance) = self.get_entity(self.id) {
281 if let Some(instance) = instance.properties.get(property_name) {
282 instance.set_no_propagate(value);
283 }
284 }
285 }
286
287 fn mutability(&self, property_name: &str) -> Option<Mutability> {
288 self.get_entity(self.id)
289 .and_then(|instance| instance.properties.get(property_name).map(|p| p.value().mutability))
290 }
291
292 fn set_mutability(&self, property_name: &str, mutability: Mutability) {
293 if let Some(instance) = self.get_entity(self.id) {
294 if let Some(mut property_instance) = instance.properties.get_mut(property_name) {
295 property_instance.set_mutability(mutability);
296 }
297 }
298 }
299
300 }
303
304impl NamespacedTypeGetter for ReactiveFlowInstance {
305 fn namespaced_type(&self) -> NamespacedType {
306 self.ty.namespaced_type()
307 }
308
309 fn namespace(&self) -> Namespace {
310 self.ty.namespace()
311 }
312
313 fn path(&self) -> Namespace {
314 self.ty.path()
315 }
316
317 fn type_name(&self) -> NamespaceSegment {
318 self.ty.type_name()
319 }
320}
321
322impl TypeDefinitionGetter for ReactiveFlowInstance {
323 fn type_definition(&self) -> TypeDefinition {
324 self.ty.type_definition()
325 }
326
327 fn type_id_type() -> TypeIdType {
328 TypeIdType::FlowType
329 }
330}
331
332impl TypeDefinitionGetter for &ReactiveFlowInstance {
333 fn type_definition(&self) -> TypeDefinition {
334 self.ty.type_definition()
335 }
336
337 fn type_id_type() -> TypeIdType {
338 TypeIdType::FlowType
339 }
340}
341
342impl Display for ReactiveFlowInstance {
343 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
344 write!(f, "{}__{}", &self.ty, self.id)
345 }
346}
347
348impl TryFrom<ReactiveFlowInstance> for FlowInstance {
349 type Error = CreateFlowInstanceError;
350
351 fn try_from(reactive_flow: ReactiveFlowInstance) -> Result<Self, CreateFlowInstanceError> {
352 let wrapper = reactive_flow.get_entity(reactive_flow.id);
353 if wrapper.is_none() {
354 return Err(CreateFlowInstanceError::CantGetWrapperEntity(reactive_flow.id));
355 }
356 let wrapper = wrapper.unwrap();
357 let entity_instance: EntityInstance = wrapper.clone().into();
358 let mut flow_instance = FlowInstance::from(entity_instance);
359 flow_instance.description = wrapper.description.clone();
360 reactive_flow.entity_instances.read().unwrap().iter().for_each(|(_, reactive_entity)| {
361 if reactive_entity.id != reactive_flow.id {
362 let entity_instance: EntityInstance = reactive_entity.into();
363 flow_instance.entity_instances.push(entity_instance);
364 }
365 });
366 reactive_flow.relation_instances.read().unwrap().iter().for_each(|(_, reactive_instance)| {
367 let relation_instance = RelationInstance::from(reactive_instance);
368 flow_instance.relation_instances.push(relation_instance);
369 });
370 Ok(flow_instance)
371 }
372}
373
374impl TryFrom<&ReactiveFlowInstance> for FlowInstance {
375 type Error = CreateFlowInstanceError;
376
377 fn try_from(reactive_flow: &ReactiveFlowInstance) -> Result<Self, CreateFlowInstanceError> {
378 let wrapper = reactive_flow.get_entity(reactive_flow.id);
379 if wrapper.is_none() {
380 return Err(CreateFlowInstanceError::CantGetWrapperEntity(reactive_flow.id));
381 }
382 let wrapper = wrapper.unwrap();
383 let entity_instance: EntityInstance = wrapper.clone().into();
384 let mut flow_instance = FlowInstance::from(entity_instance);
385 flow_instance.description = wrapper.description.clone();
386 reactive_flow.entity_instances.read().unwrap().iter().for_each(|(_, reactive_entity)| {
387 if reactive_entity.id != reactive_flow.id {
388 let entity_instance: EntityInstance = reactive_entity.into();
389 flow_instance.entity_instances.push(entity_instance);
390 }
391 });
392 reactive_flow.relation_instances.read().unwrap().iter().for_each(|(_, reactive_relation)| {
393 let relation_instance: RelationInstance = reactive_relation.into();
394 flow_instance.relation_instances.push(relation_instance);
395 });
396 Ok(flow_instance)
397 }
398}
399
400#[derive(Clone)]
401pub struct ReactiveFlow(Arc<ReactiveFlowInstance>);
402
403impl ReactiveFlow {
404 pub fn new(wrapper_entity_instance: ReactiveEntity) -> Self {
405 ReactiveFlowInstance::new(wrapper_entity_instance).into()
406 }
407}
408
409impl NamedInstanceContainer for ReactiveFlow {
410 fn name(&self) -> String {
411 self.name.clone()
412 }
413
414 fn description(&self) -> String {
415 self.description.clone()
416 }
417}
418
419impl Deref for ReactiveFlow {
420 type Target = Arc<ReactiveFlowInstance>;
421
422 fn deref(&self) -> &Self::Target {
423 &self.0
424 }
425}
426
427impl ReactiveInstanceUnidentifiable for ReactiveFlow {}
428
429impl ReactiveInstance<Uuid> for ReactiveFlow {
430 fn id(&self) -> Uuid {
431 self.id
432 }
433}
434
435impl ReactivePropertyContainer for ReactiveFlow {
436 fn tick_checked(&self) {
437 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
438 wrapper_entity_instance.tick_checked();
439 }
440 }
441
442 fn tick(&self) {
443 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
444 wrapper_entity_instance.tick();
445 }
446 }
447
448 fn has_property(&self, name: &str) -> bool {
449 self.get_wrapper_entity_instance()
450 .map(|wrapper_entity| wrapper_entity.has_property(name))
451 .unwrap_or_default()
452 }
453
454 fn add_property(&self, name: &str, mutability: Mutability, value: Value) {
455 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
456 wrapper_entity_instance.add_property(name, mutability, value);
457 }
458 }
459
460 fn add_property_by_type(&self, property: &PropertyType) {
461 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
462 wrapper_entity_instance.add_property_by_type(property);
463 }
464 }
465
466 fn remove_property(&self, name: &str) {
467 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
468 wrapper_entity_instance.remove_property(name);
469 }
470 }
471
472 fn observe_with_handle<F>(&self, name: &str, subscriber: F, handle_id: u128)
473 where
474 F: FnMut(&Value) + 'static + Send,
475 {
476 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
477 wrapper_entity_instance.observe_with_handle(name, subscriber, handle_id);
478 }
479 }
480
481 fn remove_observer(&self, name: &str, handle_id: u128) {
482 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
483 wrapper_entity_instance.remove_observer(name, handle_id);
484 }
485 }
486
487 fn remove_observers(&self, name: &str) {
488 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
489 wrapper_entity_instance.remove_observers(name);
490 }
491 }
492
493 fn remove_all_observers(&self) {
494 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
495 wrapper_entity_instance.remove_all_observers();
496 }
497 }
498}
499
500impl ComponentContainer for ReactiveFlow {
501 fn get_components(&self) -> ComponentTypeIds {
502 self.get_wrapper_entity_instance()
503 .map(|wrapper_entity| wrapper_entity.get_components())
504 .unwrap_or_default()
505 }
506
507 fn add_component(&self, ty: ComponentTypeId) {
508 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
509 wrapper_entity_instance.add_component(ty);
510 }
511 }
512
513 fn add_component_with_properties(&self, component: &Component) {
514 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
515 wrapper_entity_instance.add_component_with_properties(component);
516 }
517 }
518
519 fn remove_component(&self, ty: &ComponentTypeId) {
520 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
521 wrapper_entity_instance.remove_component(ty);
522 }
523 }
524
525 fn is_a(&self, ty: &ComponentTypeId) -> bool {
526 self.get_wrapper_entity_instance()
527 .map(|wrapper_entity| wrapper_entity.is_a(ty))
528 .unwrap_or_default()
529 }
530
531 fn is_all(&self, tys: &ComponentTypeIds) -> bool {
532 self.get_wrapper_entity_instance()
533 .map(|wrapper_entity| wrapper_entity.is_all(&tys))
534 .unwrap_or_default()
535 }
536}
537
538impl BehaviourTypesContainer for ReactiveFlow {
539 fn get_behaviours(&self) -> Vec<BehaviourTypeId> {
540 self.get_wrapper_entity_instance()
541 .map(|wrapper_entity| wrapper_entity.get_behaviours())
542 .unwrap_or_default()
543 }
544
545 fn add_behaviour(&self, ty: BehaviourTypeId) {
546 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
547 wrapper_entity_instance.add_behaviour(ty);
548 }
549 }
550
551 fn remove_behaviour(&self, ty: &BehaviourTypeId) {
552 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
553 wrapper_entity_instance.remove_behaviour(ty);
554 }
555 }
556
557 fn behaves_as(&self, ty: &BehaviourTypeId) -> bool {
558 self.get_wrapper_entity_instance()
559 .map(|wrapper_entity| wrapper_entity.behaves_as(ty))
560 .unwrap_or_default()
561 }
562
563 fn behaves_as_all(&self, tys: &BehaviourTypeIds) -> bool {
564 self.get_wrapper_entity_instance()
565 .map(|wrapper_entity| wrapper_entity.behaves_as_all(tys))
566 .unwrap_or_default()
567 }
568}
569
570impl PropertyInstanceGetter for ReactiveFlow {
571 fn get(&self, property_name: &str) -> Option<Value> {
572 self.get_wrapper_entity_instance().and_then(|wrapper_entity| wrapper_entity.get(property_name))
573 }
574
575 fn as_bool(&self, property_name: &str) -> Option<bool> {
576 self.get_wrapper_entity_instance()
577 .and_then(|wrapper_entity| wrapper_entity.as_bool(property_name))
578 }
579
580 fn as_u64(&self, property_name: &str) -> Option<u64> {
581 self.get_wrapper_entity_instance()
582 .and_then(|wrapper_entity| wrapper_entity.as_u64(property_name))
583 }
584
585 fn as_i64(&self, property_name: &str) -> Option<i64> {
586 self.get_wrapper_entity_instance()
587 .and_then(|wrapper_entity| wrapper_entity.as_i64(property_name))
588 }
589
590 fn as_f64(&self, property_name: &str) -> Option<f64> {
591 self.get_wrapper_entity_instance()
592 .and_then(|wrapper_entity| wrapper_entity.as_f64(property_name))
593 }
594
595 fn as_string(&self, property_name: &str) -> Option<String> {
596 self.get_wrapper_entity_instance()
597 .and_then(|wrapper_entity| wrapper_entity.as_string(property_name))
598 }
599
600 fn as_array(&self, property_name: &str) -> Option<Vec<Value>> {
601 self.get_wrapper_entity_instance()
602 .and_then(|wrapper_entity| wrapper_entity.as_array(property_name))
603 }
604
605 fn as_object(&self, property_name: &str) -> Option<Map<String, Value>> {
606 self.get_wrapper_entity_instance()
607 .and_then(|wrapper_entity| wrapper_entity.as_object(property_name))
608 }
609}
610
611impl PropertyInstanceSetter for ReactiveFlow {
612 fn set_checked(&self, property_name: &str, value: Value) {
613 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
614 wrapper_entity_instance.set_checked(property_name, value);
615 }
616 }
617
618 fn set(&self, property_name: &str, value: Value) {
619 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
620 wrapper_entity_instance.set(property_name, value);
621 }
622 }
623
624 fn set_no_propagate_checked(&self, property_name: &str, value: Value) {
625 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
626 wrapper_entity_instance.set_no_propagate_checked(property_name, value);
627 }
628 }
629
630 fn set_no_propagate(&self, property_name: &str, value: Value) {
631 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
632 wrapper_entity_instance.set_no_propagate(property_name, value);
633 }
634 }
635
636 fn mutability(&self, property_name: &str) -> Option<Mutability> {
637 self.get_wrapper_entity_instance()
638 .and_then(|wrapper_entity| wrapper_entity.mutability(property_name))
639 }
640
641 fn set_mutability(&self, property_name: &str, mutability: Mutability) {
642 if let Some(wrapper_entity_instance) = self.get_wrapper_entity_instance() {
643 wrapper_entity_instance.set_mutability(property_name, mutability);
644 }
645 }
646
647 }
650
651impl NamespacedTypeGetter for ReactiveFlow {
652 fn namespaced_type(&self) -> NamespacedType {
653 self.ty.namespaced_type()
654 }
655
656 fn namespace(&self) -> Namespace {
657 self.ty.namespace()
658 }
659
660 fn path(&self) -> Namespace {
661 self.ty.path()
662 }
663
664 fn type_name(&self) -> NamespaceSegment {
665 self.ty.type_name()
666 }
667}
668
669impl TypeDefinitionGetter for ReactiveFlow {
670 fn type_definition(&self) -> TypeDefinition {
671 self.ty.type_definition()
672 }
673
674 fn type_id_type() -> TypeIdType {
675 TypeIdType::FlowType
676 }
677}
678
679impl Display for ReactiveFlow {
680 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
681 write!(f, "{}__{}", &self.ty, self.id)
682 }
683}
684
685impl From<ReactiveFlowInstance> for ReactiveFlow {
686 fn from(reactive_flow: ReactiveFlowInstance) -> Self {
687 ReactiveFlow(Arc::new(reactive_flow))
688 }
689}
690
691impl TryFrom<FlowInstance> for ReactiveFlow {
692 type Error = ReactiveFlowConstructionError;
693
694 fn try_from(flow_instance: FlowInstance) -> Result<Self, Self::Error> {
695 ReactiveFlowInstance::try_from(flow_instance).map(|reactive_flow| reactive_flow.into())
696 }
697}
698
699impl TryFrom<ReactiveFlow> for FlowInstance {
700 type Error = CreateFlowInstanceError;
701
702 fn try_from(reactive_flow: ReactiveFlow) -> Result<Self, CreateFlowInstanceError> {
703 FlowInstance::try_from(reactive_flow.0.deref())
704 }
705}