feat: Separate convert into from and to
This commit is contained in:
25
src/lib.rs
25
src/lib.rs
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user