ebi/
parsing.rs

1use anyhow::Error;
2use std::str::FromStr;
3
4use crate::{fraction_enum::FractionEnum, fraction_exact::FractionExact, fraction_f64::FractionF64};
5
6#[derive(Clone)]
7pub struct FractionNotParsedYet {
8    pub s: String,
9}
10
11impl FromStr for FractionNotParsedYet {
12    type Err = Error;
13
14    fn from_str(s: &str) -> std::prelude::v1::Result<Self, Self::Err> {
15        Ok(Self { s: s.to_string() })
16    }
17}
18
19impl TryFrom<&FractionNotParsedYet> for FractionEnum {
20    type Error = Error;
21
22    fn try_from(value: &FractionNotParsedYet) -> std::result::Result<Self, Self::Error> {
23        Self::from_str(&value.s)
24    }
25}
26
27impl TryFrom<&FractionNotParsedYet> for FractionExact {
28    type Error = Error;
29
30    fn try_from(value: &FractionNotParsedYet) -> std::result::Result<Self, Self::Error> {
31        Self::from_str(&value.s)
32    }
33}
34
35impl TryFrom<&FractionNotParsedYet> for FractionF64 {
36    type Error = Error;
37
38    fn try_from(value: &FractionNotParsedYet) -> std::result::Result<Self, Self::Error> {
39        Ok(Self::from_str(&value.s)?)
40    }
41}