fn parse_color(args: &[&str]) -> ObjResult<MtlColor> {
    if args.is_empty() {
        make_error!(WrongNumberOfArguments, "Expected at least 1 argument");
    }

    Ok(match args[0] {
        "xyz" => match parse_args(&args[1..])?[..] {
            [x] => MtlColor::Xyz(x, x, x),
            [x, y, z] => MtlColor::Xyz(x, y, z),
            _ => make_error!(WrongNumberOfArguments, "Expected 1 or 3 color values"),
        },

        "spectral" => match args[1..] {
            [name] => MtlColor::Spectral(name.to_string(), 1.0),
            [name, multiplier] => MtlColor::Spectral(name.to_string(), multiplier.parse()?),
            _ => make_error!(WrongNumberOfArguments, "Expected 1 or 2 arguments"),
        },

        _ => match parse_args(args)?[..] {
            [r] => MtlColor::Rgb(r, r, r),
            [r, g, b] => MtlColor::Rgb(r, g, b),
            _ => make_error!(WrongNumberOfArguments, "Expected 1 or 3 color values"),
        },
    })
}
/// Parses a color from the arguments of a statement
Parses a color from the arguments of a statement
Parses a color from the arguments of a statement
fn parse_color(args: &[&str]) -> ObjResult<MtlColor> {
    if args.is_empty() {
        make_error!(WrongNumberOfArguments, "Expected at least 1 argument");
    }
    Ok(match args[0] {
        "xyz" => match parse_args(&args[1..])?[..] {
            [x] => MtlColor::Xyz(x, x, x),
            [x, y, z] => MtlColor::Xyz(x, y, z),
            _ => make_error!(WrongNumberOfArguments, "Expected 1 or 3 color values"),
        },
        "spectral" => match args[1..] {
            [name] => MtlColor::Spectral(name.to_string(), 1.0),
            [name, multiplier] => MtlColor::Spectral(name.to_string(), multiplier.parse()?),
            _ => make_error!(WrongNumberOfArguments, "Expected 1 or 2 arguments"),
        },
        _ => match parse_args(args)?[..] {
            [r] => MtlColor::Rgb(r, r, r),
            [r, g, b] => MtlColor::Rgb(r, g, b),
            _ => make_error!(WrongNumberOfArguments, "Expected 1 or 3 color values"),
        },
    })
}
fn parse_color ( args : & [ & str ] ) -> ObjResult < MtlColor > { if args . is_empty ( ) { make_error ! ( WrongNumberOfArguments " " ) ; } Ok ( match args [ 0 ] { " " => match parse_args ( & args [ 1 .. ] ) ? [ .. ] { [ x ] => MtlColor :: Xyz ( x , x , x ) , [ x , y , z ] => MtlColor :: Xyz ( x , y , z ) , _ => make_error ! ( WrongNumberOfArguments " " ) , } , " " => match args [ 1 .. ] { [ name ] => MtlColor :: Spectral ( name . to_string ( ) , 1.0 ) , [ name , multiplier ] => MtlColor :: Spectral ( name . to_string ( ) , multiplier . parse ( ) ? ) , _ => make_error ! ( WrongNumberOfArguments " " ) , } , _ => match parse_args ( args ) ? [ .. ] { [ r ] => MtlColor :: Rgb ( r , r , r ) , [ r , g , b ] => MtlColor :: Rgb ( r , g , b ) , _ => make_error ! ( WrongNumberOfArguments " " ) , } , } ) }
Parses a color from the arguments of a statement
Parses a color from the arguments of a statement
args
&[&str]