style/values/specified/
ratio.rs1use crate::parser::{Parse, ParserContext};
10use crate::values::generics::ratio::Ratio as GenericRatio;
11use crate::values::specified::NonNegativeNumber;
12use crate::One;
13use cssparser::Parser;
14use style_traits::ParseError;
15
16pub type Ratio = GenericRatio<NonNegativeNumber>;
18
19impl Parse for Ratio {
20 fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
21 let a = NonNegativeNumber::parse(context, input)?;
22 let b = match input.try_parse(|input| input.expect_delim('/')) {
23 Ok(()) => NonNegativeNumber::parse(context, input)?,
24 _ => One::one(),
25 };
26
27 Ok(GenericRatio(a, b))
28 }
29}