-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
75 lines (62 loc) · 1.84 KB
/
mod.rs
File metadata and controls
75 lines (62 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub mod execution;
pub mod views;
pub mod views_manager;
use core::fmt;
use std::collections::HashMap;
use views::{DataView, DynDataView};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ViewId(usize);
impl From<usize> for ViewId {
fn from(id: usize) -> Self {
ViewId(id)
}
}
impl Into<usize> for ViewId {
fn into(self) -> usize {
self.0
}
}
/// High level description of data views and their connections into the
/// pipeline.
///
/// Data views are analog to pipeline nodes, with the main difference that they
/// render into their own tab. They are very similar to pipeline nodes, but have
/// their own management system and execution system. They can connect into the
/// pipeline.
pub struct DataViewsState {
views: HashMap<ViewId, Box<dyn DynDataView>>,
}
impl DataViewsState {
pub fn new() -> Self {
Self {
views: HashMap::new(),
}
}
pub fn get_new_view_id(&self) -> ViewId {
self.views
.keys()
.max()
.map_or(ViewId::from(0), |&id| (Into::<usize>::into(id) + 1).into())
}
fn add_view(&mut self, view: Box<dyn DynDataView>) -> ViewId {
let id = self.get_new_view_id();
self.views.insert(id, view);
id
}
pub fn get(&self, view_id: ViewId) -> Option<&dyn DynDataView> {
self.views.get(&view_id).map(|v| v.as_ref())
}
pub fn get_mut(&mut self, view_id: ViewId) -> Option<&mut dyn DynDataView> {
self.views.get_mut(&view_id).map(|v| v.as_mut())
}
pub fn clear(&mut self) {
self.views.clear();
}
}
impl fmt::Debug for DataViewsState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("DataViewsState")
.field("views", &self.views.keys().collect::<Vec<_>>())
.finish()
}
}