feat: Add convert on Tooth
This commit is contained in:
26
src/lib.rs
26
src/lib.rs
@@ -1,16 +1,10 @@
|
|||||||
|
#[derive(Copy, Clone)]
|
||||||
pub enum NotationKind {
|
pub enum NotationKind {
|
||||||
Iso,
|
Iso,
|
||||||
Palmer,
|
|
||||||
Uns,
|
Uns,
|
||||||
Alphanumeric,
|
Alphanumeric,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum TeethKind {
|
|
||||||
Canine,
|
|
||||||
Incisor,
|
|
||||||
Premolar,
|
|
||||||
Molar,
|
|
||||||
}
|
|
||||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||||
pub enum QuadrantKind {
|
pub enum QuadrantKind {
|
||||||
TopLeft,
|
TopLeft,
|
||||||
@@ -26,7 +20,7 @@ pub struct Tooth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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) {
|
if let Err(err) = Tooth::check_tooth_number(number, permanent) {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
@@ -235,6 +229,22 @@ impl Tooth {
|
|||||||
};
|
};
|
||||||
quadrant.to_owned() + &number
|
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)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user