feat: Separate convert into from and to

This commit is contained in:
2022-08-03 15:54:52 +02:00
parent 3e5433a886
commit 970b7f6f64
2 changed files with 32 additions and 10 deletions

View File

@@ -230,18 +230,27 @@ impl Tooth {
quadrant.to_owned() + &number
}
pub fn convert(from: &NotationKind, to: &NotationKind, value: &str) -> Result<String, String> {
let tooth_result = match from {
pub fn from(value: &str, from: &NotationKind) -> Result<Self, String> {
match from {
NotationKind::Iso => Tooth::from_iso(value),
NotationKind::Uns => Tooth::from_uns(value),
NotationKind::Alphanumeric => Tooth::from_alphanumeric(value),
};
}
}
pub fn to(&self, to: &NotationKind) -> String {
match to {
NotationKind::Iso => self.to_iso(),
NotationKind::Uns => self.to_uns(),
NotationKind::Alphanumeric => self.to_alphanumeric(),
}
}
#[deprecated(since = "1.0.0", note = "Use 'to' and 'from' directly")]
pub fn convert(from: &NotationKind, to: &NotationKind, value: &str) -> Result<String, String> {
let tooth_result = Tooth::from(value, from);
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()),
},
Ok(tooth) => Ok(tooth.to(to)),
Err(err) => Err(err),
}
}