feat: Add convert on Tooth

This commit is contained in:
2022-07-26 18:23:03 +02:00
parent 144c56b517
commit 51f2641804

View File

@@ -1,16 +1,10 @@
#[derive(Copy, Clone)]
pub enum NotationKind {
Iso,
Palmer,
Uns,
Alphanumeric,
}
pub enum TeethKind {
Canine,
Incisor,
Premolar,
Molar,
}
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum QuadrantKind {
TopLeft,
@@ -26,7 +20,7 @@ pub struct Tooth {
}
impl Tooth {
pub fn new(number: u8, quadrant: QuadrantKind, permanent: bool) -> Result<Tooth, String> {
fn _new(number: u8, quadrant: QuadrantKind, permanent: bool) -> Result<Tooth, String> {
if let Err(err) = Tooth::check_tooth_number(number, permanent) {
return Err(err);
}
@@ -235,6 +229,22 @@ impl Tooth {
};
quadrant.to_owned() + &number
}
pub fn convert(from: &NotationKind, to: &NotationKind, value: &str) -> Result<String, String> {
let tooth_result = match from {
NotationKind::Iso => Tooth::from_iso(value),
NotationKind::Uns => Tooth::from_uns(value),
NotationKind::Alphanumeric => Tooth::from_alphanumeric(value),
};
match tooth_result {
Ok(tooth) => match to {
NotationKind::Iso => Ok(tooth.to_iso()),
NotationKind::Uns => Ok(tooth.to_uns()),
NotationKind::Alphanumeric => Ok(tooth.to_alphanumeric()),
},
Err(err) => Err(err),
}
}
}
#[cfg(test)]