RationalParse

Trait RationalParse 

Source
pub trait RationalParse: Sized {
    // Required method
    fn from_str_flex(s: &str) -> Result<Self, ParseRatioError>;
}
Expand description

A trait for parsing a string into a rational number with flexible formats.

This trait extends num_rational::Ratio to support parsing strings in formats accepted by Python’s fractions.Fraction class, including:

  • Fractions: "1/2"
  • Decimals: "1.5"
  • Scientific notation: "1.2e-3", "1E5"

Required Methods§

Source

fn from_str_flex(s: &str) -> Result<Self, ParseRatioError>

Parses a string into a rational number.

The input string can be in various formats:

  • "-35/4" (Fraction)
  • "3.1415" (Decimal)
  • "-47e-2" (Scientific notation)
§Errors

Returns ParseRatioError if the string is not a valid rational number string or if it represents a valid number that cannot be represented by the target type (e.g. overflow).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> RationalParse for Ratio<T>

Implementors§