88mod extractors;
99pub use extractors:: Files ;
1010
11- #[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
12- pub enum ECAD {
13- // * Keep these in alphabetical order
14- #[ serde( rename = "3d" ) ]
15- D3 , // 3D
16- #[ serde( rename = "eagle" ) ]
17- EAGLE ,
18- #[ serde( rename = "easyeda" ) ]
19- EASYEDA ,
20- #[ serde( rename = "kicad" ) ]
21- KICAD ,
22- #[ serde( rename = "zip" ) ]
23- ZIP ,
24- }
11+ macro_rules! ecad {
12+ ( [ $( ( $variant: tt, $variant_literal: literal) ) ,* ] ) => {
13+ #[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
14+ pub enum ECAD {
15+ $(
16+ #[ serde( rename = $variant_literal) ]
17+ $variant,
18+ ) *
19+ }
2520
26- impl TryFrom < & str > for ECAD {
27- type Error = Error ;
21+ impl :: core :: convert :: TryFrom <& str > for ECAD {
22+ type Error = Error ;
2823
29- fn try_from ( value : & str ) -> std :: result:: Result < Self , Self :: Error > {
30- match value. to_lowercase ( ) . as_str ( ) {
31- "3d" => Ok ( ECAD :: D3 ) ,
32- "eagle" => Ok ( ECAD :: EAGLE ) ,
33- "easyeda" => Ok ( ECAD :: EASYEDA ) ,
34- "kicad" => Ok ( ECAD :: KICAD ) ,
35- "zip" => Ok ( ECAD :: ZIP ) ,
36- _ => Err ( Error :: EcadNotFound ) ,
24+ fn try_from( value: & str ) -> :: core :: result:: Result <Self , Self :: Error > {
25+ match value. to_lowercase( ) . as_str( ) {
26+ $ (
27+ $variant_literal => Ok ( ECAD :: $variant ) ,
28+ ) *
29+ _ => Err ( Error :: EcadNotFound ) ,
30+ }
31+ }
3732 }
38- }
39- }
4033
41- impl fmt:: Display for ECAD {
42- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
43- write ! (
44- f,
45- "{}" ,
46- match & self {
47- Self :: D3 => "3d" ,
48- Self :: EAGLE => "eagle" ,
49- Self :: EASYEDA => "easyeda" ,
50- Self :: KICAD => "kicad" ,
51- Self :: ZIP => "zip" ,
34+ impl :: core :: fmt:: Display for ECAD {
35+ fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> :: core :: fmt:: Result {
36+ write!(
37+ f,
38+ "{}" ,
39+ match & self {
40+ $ (
41+ Self :: $variant => $variant_literal ,
42+ ) *
43+ }
44+ )
5245 }
53- )
54- }
46+ }
47+
48+ } ;
5549}
5650
51+ ecad ! ( [
52+ ( D3 , "3d" ) ,
53+ ( DesignSpark , "designspark" ) ,
54+ ( Eagle , "eagle" ) ,
55+ ( EasyEDA , "easyeda" ) ,
56+ ( KiCad , "kicad" ) ,
57+ ( Zip , "zip" )
58+ ] ) ;
59+
5760#[ derive( Debug , Clone , PartialEq ) ]
5861pub struct Format {
5962 pub output_path : PathBuf ,
@@ -66,46 +69,46 @@ pub struct Format {
6669
6770impl Format {
6871 pub fn from_ecad < P : Into < PathBuf > > ( ecad : ECAD , output_path : P ) -> Self {
69- // let f = format.into().to_lowercase();
70-
7172 // * Keep these in alphabetical order
7273 match ecad {
7374 ECAD :: D3 => Self {
7475 output_path : output_path. into ( ) ,
75- // name: f,
76- ecad : ECAD :: D3 ,
76+ ecad,
7777 create_folder : true ,
7878 match_path : "3D" ,
7979 ignore : vec ! [ ] ,
8080 } ,
81- ECAD :: EAGLE => Self {
81+ ECAD :: DesignSpark => Self {
82+ output_path : output_path. into ( ) ,
83+ ecad,
84+ create_folder : false ,
85+ match_path : "DesignSpark PCB" ,
86+ ignore : vec ! [ ] ,
87+ } ,
88+ ECAD :: Eagle => Self {
8289 output_path : output_path. into ( ) ,
83- // name: f,
84- ecad : ECAD :: EAGLE ,
90+ ecad,
8591 create_folder : false ,
8692 match_path : "EAGLE" ,
8793 ignore : vec ! [ "Readme.html" ] ,
8894 } ,
89- ECAD :: EASYEDA => Self {
95+ ECAD :: EasyEDA => Self {
9096 output_path : output_path. into ( ) ,
91- // name: f,
92- ecad : ECAD :: EASYEDA ,
97+ ecad,
9398 create_folder : false ,
9499 match_path : "EasyEDA" ,
95100 ignore : vec ! [ "Readme.html" ] ,
96101 } ,
97- ECAD :: KICAD => Self {
102+ ECAD :: KiCad => Self {
98103 output_path : output_path. into ( ) ,
99- // name: f,
100- ecad : ECAD :: KICAD ,
104+ ecad,
101105 create_folder : true ,
102106 match_path : "KiCad" ,
103107 ignore : vec ! [ ] ,
104108 } ,
105- ECAD :: ZIP => Self {
109+ ECAD :: Zip => Self {
106110 output_path : output_path. into ( ) ,
107- // name: f,
108- ecad : ECAD :: ZIP ,
111+ ecad,
109112 create_folder : false ,
110113 match_path : "" ,
111114 ignore : vec ! [ ] ,
@@ -117,10 +120,12 @@ impl Format {
117120 match & self . ecad {
118121 // * Keep these in alphabetical order
119122 ECAD :: D3 => extractors:: d3:: extract ( & self , files, file_path, item) ?,
120- ECAD :: EAGLE => extractors:: eagle:: extract ( & self , files, file_path, item) ?,
121- ECAD :: EASYEDA => extractors:: easyeda:: extract ( & self , files, file_path, item) ?,
122- ECAD :: KICAD => extractors:: kicad:: extract ( & self , files, file_path, item) ?,
123- ECAD :: ZIP => unreachable ! ( "ZIP not handled!" ) , // ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
123+ ECAD :: DesignSpark => extractors:: designspark:: extract ( & self , files, file_path, item) ?,
124+ ECAD :: Eagle => extractors:: eagle:: extract ( & self , files, file_path, item) ?,
125+ ECAD :: EasyEDA => extractors:: easyeda:: extract ( & self , files, file_path, item) ?,
126+ ECAD :: KiCad => extractors:: kicad:: extract ( & self , files, file_path, item) ?,
127+ ECAD :: Zip => unreachable ! ( "ZIP not handled!" ) ,
128+ // ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
124129 } ;
125130
126131 Ok ( ( ) )
0 commit comments