fui_core/children/
children_source.rs1use std::cell::RefCell;
2use std::rc::Rc;
3
4use crate::control::ControlObject;
5use crate::observable::ObservableVec;
6use crate::{
7 observable::ObservableCollectionExt, ObservableCollectionFlatMap, ObservableCollectionMap,
8};
9use crate::{view::ViewModel, ObservableCollection, Property};
10
11impl<V: ViewModel + 'static> From<Vec<Rc<V>>> for Box<dyn ObservableCollection<Rc<V>>> {
15 fn from(collection: Vec<Rc<V>>) -> Self {
16 Box::new(collection) as Box<dyn ObservableCollection<Rc<V>>>
17 }
18}
19
20impl<V: ViewModel + 'static> From<&Vec<Rc<V>>>
21 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
22{
23 fn from(src: &Vec<Rc<V>>) -> Self {
24 Box::new(src.map(|vm| ViewModel::create_view(vm)))
25 }
26}
27
28impl<V> From<&ObservableVec<Rc<V>>>
32 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
33where
34 V: 'static + ViewModel,
35{
36 fn from(src: &ObservableVec<Rc<V>>) -> Self {
37 Box::new(src.map(|vm| ViewModel::create_view(vm)))
38 }
39}
40
41impl From<&ObservableVec<Rc<RefCell<dyn ControlObject>>>>
42 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
43{
44 fn from(src: &ObservableVec<Rc<RefCell<dyn ControlObject>>>) -> Self {
45 Box::new(src.map(|el| el.clone()))
46 }
47}
48
49impl<V> From<ObservableCollectionMap<Rc<V>>>
54 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
55where
56 V: 'static + ViewModel,
57{
58 fn from(src: ObservableCollectionMap<Rc<V>>) -> Self {
59 Box::new(src.map(|vm| ViewModel::create_view(vm)))
60 }
61}
62
63impl From<ObservableCollectionMap<Rc<RefCell<dyn ControlObject>>>>
64 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
65{
66 fn from(src: ObservableCollectionMap<Rc<RefCell<dyn ControlObject>>>) -> Self {
67 Box::new(src)
68 }
69}
70
71impl<V> From<&ObservableCollectionMap<Rc<V>>>
72 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
73where
74 V: 'static + ViewModel,
75{
76 fn from(src: &ObservableCollectionMap<Rc<V>>) -> Self {
77 Box::new(src.map(|vm| ViewModel::create_view(vm)))
78 }
79}
80
81impl From<&ObservableCollectionMap<Rc<RefCell<dyn ControlObject>>>>
82 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
83{
84 fn from(src: &ObservableCollectionMap<Rc<RefCell<dyn ControlObject>>>) -> Self {
85 Box::new(src.map(|el| el.clone()))
86 }
87}
88
89impl From<ObservableCollectionFlatMap<Rc<RefCell<dyn ControlObject>>>>
94 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
95{
96 fn from(src: ObservableCollectionFlatMap<Rc<RefCell<dyn ControlObject>>>) -> Self {
97 Box::new(src)
98 }
99}
100
101impl From<&ObservableCollectionFlatMap<Rc<RefCell<dyn ControlObject>>>>
102 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
103{
104 fn from(src: &ObservableCollectionFlatMap<Rc<RefCell<dyn ControlObject>>>) -> Self {
105 Box::new(src.map(|el| el.clone()))
106 }
107}
108
109impl From<&Property<Rc<RefCell<dyn ControlObject>>>>
114 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
115{
116 fn from(src: &Property<Rc<RefCell<dyn ControlObject>>>) -> Self {
117 Box::new(src.clone())
118 }
119}
120
121impl<V> From<&Property<Rc<V>>> for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
122where
123 V: 'static + ViewModel + PartialEq,
124{
125 fn from(src: &Property<Rc<V>>) -> Self {
126 Box::new(src.map(|vm| ViewModel::create_view(vm)))
127 }
128}
129
130impl<V> From<&Property<Option<Rc<V>>>>
131 for Box<dyn ObservableCollection<Rc<RefCell<dyn ControlObject>>>>
132where
133 V: 'static + ViewModel + PartialEq,
134{
135 fn from(src: &Property<Option<Rc<V>>>) -> Self {
136 Box::new(src.map(|vm| ViewModel::create_view(vm)))
137 }
138}