Open younies opened 11 months ago
Discussion:
@sffc , for MeasureUnitParser
, we can have MeasureUnitParser::parse_bytes(&self, bytes: &[u8]) --> Result<MeasureUnit>
and also MeasureUnitParser::parse_str(&self, id : &str) --> Result<>
--> this is an implementation for FromStr
trait.
NOTE: we need a MeasureUnitParser
that takes the units provider and parse the strings to return MeasureUnit
.
Also, for the Converter
, we need ConverterFactory
File a TODO issue to split the data between the MeasureUnitParser
and ConverterFactory
and start with
fn convert_f64(&self, value: f64) --> f64
fn convert_big_rational(&self, value: BigRational) --> BigRational
LGTM tentatively : @younies , @sffc , @robertbastian , @Manishearth
Convert(input: IcuRatio) --> IcuRatio.
IcuRatio::from_f64()
IcuRatio::to_f64()
IcuRatio::to_u64()
Converter::convert_f64(input: f64) --> f64.
Converter::convert_exact(input: IcuRatio) -> IcuRatio
conv.convert_exact(IcuRatio::fraction(7, 3))
conv.convert_exact(IcuRatio::from(7).pow(-4)))
conv.convert_f64(10e-4))
pub struct IcuRatio(pub BigRational);
No IcuRatio on FFI
// String syntax: [-]iii.fffE[-]eee
Converter::convert_decimal(input: string) -> Result<string>
Converter::convert_f64(input: f64) -> f64
Eliminated: the user might want to use IcuRatio across multiple call sites
Converter::convert_decimal(input: FixedDecimal) -> FixedDecimal
Converter::convert_f64(input: f64) -> f64
Eliminated: FixedDecimal is not efficient for math, and it can't represent ratios like 1/3
Converter::convert_f64(input: f64) -> f64.
Converter::convert_big_rational(input: BigRational) -> BigRational
conv.convert_big_rational(...)
conv.convert_big_rational(...)
conv.convert_f64(10e-4))
Expose subset of BigRational
API over FFI as IcuRational
(bikeshed)
ICU4XBigRational
or keeping it in the namespace at leastNote: Ratio<BigInt>
has a type alias to BigRational
LGTM: @sffc @robertbastian @younies @Manishearth
I am proposing this design for the fist version of the units conversion.
First
MeasureUnit
:MeasureUnitItem
s.MeasureUnitItem
contains the following:MeasureUnit
implements afn try_from_id(id: &str) --> Result<Self, DimensionError>
Second:
Converter
Converter
implements the following functions:static fn try_from_ids( id1: &str, id2: &str) --> Result<Self, DimensionError>
static fn try_from_measunits( unit1: &MeasureUnit, unit2: &MeasureUnit) --> Result<Self, DimensionError>
static fn extract_convertibility_from_ids( id1: &str, id2: &str) --> Result<Convertibility, DimensionError>
static fn extract_convertibility_from_measunits( unit1: &MeasureUnit, unit2: &MeasureUnit --> Result<Convertibility, DimensionError>
fn convert_f64(&self, value: f64) --> f64
fn convert_BigRational(&self, value: BigRational) --> BigRational
fn convert_FixedDecimal(&self, value: FixedDecimal) --> FixedDecimal
--> postpone for now.Third:
Convertibility
enum
that contains the following fields:Convertible
Reciprocal
NotConvertible
??? --> do we need it ?Fourth:
DimensionError
enum
that contains the following fields:WrongCldrUnitId
NotConvertible