use lazy_static::lazy_static; use regex::Regex; use serde::{Deserialize, Serialize}; use super::util::letters_to_num; #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug, Hash)] pub struct Well { pub row: u8, pub col: u8, } impl Well { pub fn string_well_to_pt(input: &str) -> Option { lazy_static! { static ref REGEX: Regex = Regex::new(r"([A-Z,a-z]+)(\d+)").unwrap(); // Can this be removed? static ref REGEX_ALT: Regex = Regex::new(r"(\d+)").unwrap(); } if let Some(c1) = REGEX.captures(input) { if let (Some(row), Some(col)) = (letters_to_num(&c1[1]), c1[2].parse::().ok()) { return Some(Well { row, col }); } else { return None; } } None } } impl Into for (u8, u8) { fn into(self) -> Well { Well { col: self.0, row: self.1, } } } impl Into<(u8,u8)> for Well { fn into(self) -> (u8,u8) { (self.col, self.row) } }