notation_model/
form.rs

1use std::fmt::Display;
2use std::sync::Arc;
3
4use crate::section::Section;
5
6#[derive(Debug)]
7pub struct Form {
8    pub sections: Vec<Arc<Section>>,
9}
10impl Display for Form {
11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12        write!(f, "<Form>(S:{})", self.sections.len())
13    }
14}
15impl Form {
16    pub fn new(add_ready_section: bool, proto: notation_proto::prelude::Form, tab_section: &Vec<Arc<Section>>) -> Self {
17        let mut sections = Vec::new();
18        let mut add_section =
19            |section_id: String| match tab_section.iter().find(|x| x.id == section_id).cloned() {
20                Some(section) => sections.push(section),
21                None => println!("Form::from(), bad section: {}", section_id),
22            };
23        if add_ready_section {
24            add_section(notation_proto::prelude::Section::READY_ID.to_string());
25        }
26        for section_id in proto.sections {
27            add_section(section_id);
28        }
29        Self { sections }
30    }
31}