@@ -6,7 +6,7 @@ pub mod validation;
66
77use derive_more:: { Display , Error } ;
88use indexmap:: IndexMap ;
9- use std:: { borrow:: Cow , fmt:: Debug } ;
9+ use std:: { borrow:: Cow , fmt:: Debug , str :: FromStr } ;
1010use toml:: Value as TomlValue ;
1111
1212#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
@@ -34,18 +34,21 @@ impl PrimitiveType {
3434 PrimitiveType :: Duration => "duration" ,
3535 }
3636 }
37+ }
3738
38- pub fn from_str ( s : & str ) -> Option < Self > {
39+ impl FromStr for PrimitiveType {
40+ type Err = ( ) ;
41+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
3942 match s {
40- "str" => Some ( PrimitiveType :: String ) ,
41- "int64" => Some ( PrimitiveType :: Int64 ) ,
42- "int32" => Some ( PrimitiveType :: Int32 ) ,
43- "int16" => Some ( PrimitiveType :: Int16 ) ,
44- "float64" => Some ( PrimitiveType :: Float64 ) ,
45- "float32" => Some ( PrimitiveType :: Float32 ) ,
46- "bool" => Some ( PrimitiveType :: Boolean ) ,
47- "duration" => Some ( PrimitiveType :: Duration ) ,
48- _ => None ,
43+ "str" => Ok ( PrimitiveType :: String ) ,
44+ "int64" => Ok ( PrimitiveType :: Int64 ) ,
45+ "int32" => Ok ( PrimitiveType :: Int32 ) ,
46+ "int16" => Ok ( PrimitiveType :: Int16 ) ,
47+ "float64" => Ok ( PrimitiveType :: Float64 ) ,
48+ "float32" => Ok ( PrimitiveType :: Float32 ) ,
49+ "bool" => Ok ( PrimitiveType :: Boolean ) ,
50+ "duration" => Ok ( PrimitiveType :: Duration ) ,
51+ _ => Err ( ( ) ) ,
4952 }
5053 }
5154}
@@ -70,11 +73,11 @@ pub enum Value {
7073impl Debug for Value {
7174 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
7275 match self {
73- Value :: Injected ( s) => write ! ( f, "{}" , s ) ,
76+ Value :: Injected ( s) => write ! ( f, "{s}" ) ,
7477 Value :: Set ( values) => {
7578 write ! ( f, "[" ) ?;
7679 for ( i, value) in values. iter ( ) . enumerate ( ) {
77- write ! ( f, "{:?}" , value ) ?;
80+ write ! ( f, "{value :?}" ) ?;
7881 if i < values. len ( ) - 1 {
7982 write ! ( f, ", " ) ?;
8083 }
@@ -84,17 +87,17 @@ impl Debug for Value {
8487 Value :: Array ( values) => {
8588 write ! ( f, "[" ) ?;
8689 for ( i, value) in values. iter ( ) . enumerate ( ) {
87- write ! ( f, "{:?}" , value ) ?;
90+ write ! ( f, "{value :?}" ) ?;
8891 if i < values. len ( ) - 1 {
8992 write ! ( f, ", " ) ?;
9093 }
9194 }
9295 write ! ( f, "]" )
9396 }
9497 Value :: Insert { typ, values } => {
95- write ! ( f, "insert {} = {{\n " , typ ) ?;
98+ writeln ! ( f, "insert {typ } = {{" ) ?;
9699 for ( key, value) in values {
97- write ! ( f, " {}: {:?},\n " , key , value ) ?;
100+ writeln ! ( f, " {key }: {value :?}," ) ?;
98101 }
99102 write ! ( f, "}}" )
100103 }
0 commit comments