refactor split off application state file

This commit is contained in:
2022-02-03 13:29:10 +01:00
parent a62b40f822
commit ccdd562766
3 changed files with 67 additions and 58 deletions

45
src/state/mod.rs Normal file
View File

@@ -0,0 +1,45 @@
use serde::{Serialize, Deserialize};
use crate::constants::NONE_STRING_OPTION;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnnotationZStack {
pub images: Vec<AnnotationImage>,
pub best_index: Option<usize>,
}
impl AnnotationZStack {
pub fn new() -> Self {
AnnotationZStack {
images: Vec::<AnnotationImage>::new(),
best_index: None,
}
}
pub fn push(&mut self, image: AnnotationImage) -> &mut Self {
self.images.push(image);
self
}
pub fn first(self) -> Option<AnnotationImage> {
self.images.first().map(|x| x.clone())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnnotationImage {
pub image_path: String,
pub neighbours: [Option<String>; 8],
}
impl AnnotationImage {
pub fn from_vec(image_path: String, neighbours: Vec<Option<String>>) -> Self {
let mut _neighbours = [NONE_STRING_OPTION; 8];
for (index, element) in (0..8).zip(neighbours.iter()) {
_neighbours[index] = element.clone();
}
AnnotationImage {
image_path,
neighbours: _neighbours,
}
}
}