11#![ allow( dead_code) ]
22
3- use std :: fmt;
3+ use core :: fmt;
44
55use crate :: color:: model:: Color ;
66
@@ -16,15 +16,17 @@ pub enum ColorParseError {
1616impl fmt:: Display for ColorParseError {
1717 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1818 use ColorParseError :: * ;
19- match self {
20- Empty => write ! ( f, "empty color string" ) ,
21- InvalidLength => write ! ( f, "invalid hex length" ) ,
22- InvalidHex => write ! ( f, "invalid hex digits" ) ,
23- InvalidFunc => write ! ( f, "invalid rgb()/rgba() function" ) ,
24- OutOfRange => write ! ( f, "component out of range" ) ,
25- }
19+ let msg = match self {
20+ Empty => "empty color string" ,
21+ InvalidLength => "invalid hex length" ,
22+ InvalidHex => "invalid hex digits" ,
23+ InvalidFunc => "invalid rgb()/rgba() function" ,
24+ OutOfRange => "component out of range" ,
25+ } ;
26+ f. write_str ( msg)
2627 }
2728}
29+ #[ cfg( feature = "std" ) ]
2830impl std:: error:: Error for ColorParseError { }
2931
3032/// Parse a hex color from a string.
@@ -219,7 +221,7 @@ pub fn parse_color(mut s: &str) -> Result<Color, ColorParseError> {
219221 Err ( InvalidFunc )
220222}
221223
222- impl std :: str:: FromStr for Color {
224+ impl core :: str:: FromStr for Color {
223225 type Err = ColorParseError ;
224226 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
225227 parse_color ( s)
0 commit comments