plate-tool/plate-tool-lib/src/well.rs

47 lines
1.1 KiB
Rust

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<Self> {
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::<u8>().ok()) {
return Some(Well { row, col });
} else {
return None;
}
}
None
}
}
impl Into<Well> 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)
}
}