osm_io/osm/apidb_dump/write/
current_object.rs

1pub(crate) struct CurrentObjectLine {
2    last_id: i64,
3    last_line: Option<String>,
4}
5
6impl CurrentObjectLine {
7    pub(crate) fn new() -> CurrentObjectLine {
8        CurrentObjectLine {
9            last_id: 0,
10            last_line: None,
11        }
12    }
13
14    pub(crate) fn set_last_id(&mut self, id: i64) {
15        self.last_id = id;
16    }
17
18    pub(crate) fn set_last_line(&mut self, line: String, id: i64, visible: bool) -> Option<String> {
19        let line_opt =
20            if visible {
21                std::mem::replace(&mut self.last_line, Some(line))
22            } else {
23                std::mem::take(&mut self.last_line)
24            };
25
26        if id > self.last_id {
27            line_opt
28        } else {
29            None
30        }
31    }
32
33    pub(crate) fn take(&mut self) -> Option<String> {
34        std::mem::take(&mut self.last_line)
35    }
36}
37
38pub(crate) struct CurrentObjectLines {
39    last_id: i64,
40    last_lines: Option<Vec<String>>,
41}
42
43impl CurrentObjectLines {
44    pub(crate) fn new() -> CurrentObjectLines {
45        CurrentObjectLines {
46            last_id: 0,
47            last_lines: None,
48        }
49    }
50
51    pub(crate) fn set_last_id(&mut self, id: i64) {
52        self.last_id = id;
53    }
54
55    pub(crate) fn set_last_lines(&mut self, lines: Vec<String>, id: i64, visible: bool) -> Option<Vec<String>> {
56        let lines_opt =
57            if visible {
58                std::mem::replace(&mut self.last_lines, Some(lines))
59            } else {
60                std::mem::take(&mut self.last_lines)
61            };
62
63        if id > self.last_id {
64            lines_opt
65        } else {
66            None
67        }
68    }
69
70    pub(crate) fn take(&mut self) -> Option<Vec<String>> {
71        std::mem::take(&mut self.last_lines)
72    }
73}