@@ -18,11 +18,7 @@ fn read_port(value: &Value) -> Result<PortConfiguration> {
1818 if let Value :: Table ( ref port_def) = * value {
1919 let name = match port_def. get ( "name" ) {
2020 Some ( & Value :: String ( ref name) ) => name. clone ( ) ,
21- _ => {
22- return Err (
23- ErrorKind :: ConfigurationError ( String :: from ( "Could not parse name for port" ) ) . into ( ) ,
24- )
25- }
21+ _ => return Err ( ErrorKind :: ConfigurationError ( String :: from ( "Could not parse name for port" ) ) . into ( ) ) ,
2622 } ;
2723
2824 let rxd = match port_def. get ( "rxd" ) {
@@ -48,31 +44,19 @@ fn read_port(value: &Value) -> Result<PortConfiguration> {
4844 let loopback = match port_def. get ( "loopback" ) {
4945 Some ( & Value :: Boolean ( l) ) => l,
5046 None => false ,
51- v => {
52- return Err (
53- ErrorKind :: ConfigurationError ( format ! ( "Could not parse loopback spec {:?}" , v) ) . into ( ) ,
54- )
55- }
47+ v => return Err ( ErrorKind :: ConfigurationError ( format ! ( "Could not parse loopback spec {:?}" , v) ) . into ( ) ) ,
5648 } ;
5749
5850 let tso = match port_def. get ( "tso" ) {
5951 Some ( & Value :: Boolean ( l) ) => l,
6052 None => false ,
61- v => {
62- return Err (
63- ErrorKind :: ConfigurationError ( format ! ( "Could not parse tso spec {:?}" , v) ) . into ( ) ,
64- )
65- }
53+ v => return Err ( ErrorKind :: ConfigurationError ( format ! ( "Could not parse tso spec {:?}" , v) ) . into ( ) ) ,
6654 } ;
6755
6856 let csum = match port_def. get ( "checksum" ) {
6957 Some ( & Value :: Boolean ( l) ) => l,
7058 None => false ,
71- v => {
72- return Err (
73- ErrorKind :: ConfigurationError ( format ! ( "Could not parse csum spec {:?}" , v) ) . into ( ) ,
74- )
75- }
59+ v => return Err ( ErrorKind :: ConfigurationError ( format ! ( "Could not parse csum spec {:?}" , v) ) . into ( ) ) ,
7660 } ;
7761
7862 let symmetric_queue = port_def. contains_key ( "cores" ) ;
@@ -81,13 +65,11 @@ fn read_port(value: &Value) -> Result<PortConfiguration> {
8165 "cores specified along with rx_cores and/or tx_cores for port {}" ,
8266 name
8367 ) ;
84- return Err (
85- ErrorKind :: ConfigurationError ( format ! (
86- "cores specified along with rx_cores and/or tx_cores \
87- for port {}",
88- name
89- ) ) . into ( ) ,
90- ) ;
68+ return Err ( ErrorKind :: ConfigurationError ( format ! (
69+ "cores specified along with rx_cores and/or tx_cores \
70+ for port {}",
71+ name
72+ ) ) . into ( ) ) ;
9173 }
9274
9375 fn read_queue ( queue : & Value ) -> Result < Vec < i32 > > {
@@ -139,9 +121,7 @@ fn read_port(value: &Value) -> Result<PortConfiguration> {
139121 tso : tso,
140122 } )
141123 } else {
142- Err (
143- ErrorKind :: ConfigurationError ( String :: from ( "Could not understand port spec" ) ) . into ( ) ,
144- )
124+ Err ( ErrorKind :: ConfigurationError ( String :: from ( "Could not understand port spec" ) ) . into ( ) )
145125 }
146126}
147127
@@ -154,9 +134,7 @@ pub fn read_configuration_from_str(configuration: &str, filename: &str) -> Resul
154134 Ok ( toml) => toml,
155135 Err ( error) => {
156136 println ! ( "Parse error: {} in file: {}" , error, filename) ;
157- return Err (
158- ErrorKind :: ConfigurationError ( format ! ( "Experienced {} parse errors in spec." , error) ) . into ( ) ,
159- ) ;
137+ return Err ( ErrorKind :: ConfigurationError ( format ! ( "Experienced {} parse errors in spec." , error) ) . into ( ) ) ;
160138 }
161139 } ;
162140
@@ -166,44 +144,31 @@ pub fn read_configuration_from_str(configuration: &str, filename: &str) -> Resul
166144 None => String :: from ( DEFAULT_NAME ) ,
167145 _ => {
168146 println ! ( "Could not parse name" ) ;
169- return Err (
170- ErrorKind :: ConfigurationError ( String :: from ( "Could not parse name" ) ) . into ( ) ,
171- ) ;
147+ return Err ( ErrorKind :: ConfigurationError ( String :: from ( "Could not parse name" ) ) . into ( ) ) ;
172148 }
173149 } ;
174150
175151 // Get primary core from configuration.
176152 let master_lcore = match toml. get ( "master_core" ) {
177153 Some ( & Value :: Integer ( core) ) => core as i32 ,
178- Some ( & Value :: String ( ref core) ) => {
179- match core. parse ( ) {
180- Ok ( c) => c,
181- _ => {
182- return Err (
183- ErrorKind :: ConfigurationError ( format ! ( "Could not parse {} as core" , core) ) . into ( ) ,
184- )
185- }
186- }
187- }
154+ Some ( & Value :: String ( ref core) ) => match core. parse ( ) {
155+ Ok ( c) => c,
156+ _ => return Err ( ErrorKind :: ConfigurationError ( format ! ( "Could not parse {} as core" , core) ) . into ( ) ) ,
157+ } ,
188158 None => DEFAULT_PRIMARY_CORE ,
189159 v => {
190160 println ! ( "Could not parse core" ) ;
191- return Err (
192- ErrorKind :: ConfigurationError ( format ! ( "Could not parse {:?} as core" , v) ) . into ( ) ,
193- ) ;
161+ return Err ( ErrorKind :: ConfigurationError ( format ! ( "Could not parse {:?} as core" , v) ) . into ( ) ) ;
194162 }
195163 } ;
196164
197-
198165 // Parse mempool size
199166 let pool_size = match toml. get ( "pool_size" ) {
200167 Some ( & Value :: Integer ( pool) ) => pool as u32 ,
201168 None => DEFAULT_POOL_SIZE ,
202169 _ => {
203170 println ! ( "Could parse pool size" ) ;
204- return Err (
205- ErrorKind :: ConfigurationError ( String :: from ( "Could not parse pool size" ) ) . into ( ) ,
206- ) ;
171+ return Err ( ErrorKind :: ConfigurationError ( String :: from ( "Could not parse pool size" ) ) . into ( ) ) ;
207172 }
208173 } ;
209174
@@ -213,9 +178,7 @@ pub fn read_configuration_from_str(configuration: &str, filename: &str) -> Resul
213178 None => DEFAULT_CACHE_SIZE ,
214179 _ => {
215180 println ! ( "Could parse cache size" ) ;
216- return Err (
217- ErrorKind :: ConfigurationError ( String :: from ( "Could not parse cache size" ) ) . into ( ) ,
218- ) ;
181+ return Err ( ErrorKind :: ConfigurationError ( String :: from ( "Could not parse cache size" ) ) . into ( ) ) ;
219182 }
220183 } ;
221184
@@ -225,9 +188,7 @@ pub fn read_configuration_from_str(configuration: &str, filename: &str) -> Resul
225188 None => DEFAULT_SECONDARY ,
226189 _ => {
227190 println ! ( "Could not parse whether this is a secondary process" ) ;
228- return Err (
229- ErrorKind :: ConfigurationError ( String :: from ( "Could not parse secondary processor spec" ) ) . into ( ) ,
230- ) ;
191+ return Err ( ErrorKind :: ConfigurationError ( String :: from ( "Could not parse secondary processor spec" ) ) . into ( ) ) ;
231192 }
232193 } ;
233194
@@ -239,32 +200,26 @@ pub fn read_configuration_from_str(configuration: &str, filename: &str) -> Resul
239200 if let Value :: Integer ( core) = * core {
240201 cores. push ( core as i32 )
241202 } else {
242- return Err (
243- ErrorKind :: ConfigurationError ( format ! ( "Could not parse core spec {}" , core) ) . into ( ) ,
244- ) ;
203+ return Err ( ErrorKind :: ConfigurationError ( format ! ( "Could not parse core spec {}" , core) ) . into ( ) ) ;
245204 }
246205 }
247206 cores
248207 }
249208 None => Vec :: with_capacity ( 0 ) ,
250209 _ => {
251210 println ! ( "Cores is not an array" ) ;
252- return Err (
253- ErrorKind :: ConfigurationError ( String :: from ( "Cores is not an array" ) ) . into ( ) ,
254- ) ;
211+ return Err ( ErrorKind :: ConfigurationError ( String :: from ( "Cores is not an array" ) ) . into ( ) ) ;
255212 }
256213 } ;
257214
258215 let strict = match toml. get ( "strict" ) {
259216 Some ( & Value :: Boolean ( l) ) => l,
260217 None => false ,
261218 v => {
262- return Err (
263- ErrorKind :: ConfigurationError ( format ! (
264- "Could not parse strict spec (should be boolean) {:?}" ,
265- v
266- ) ) . into ( ) ,
267- )
219+ return Err ( ErrorKind :: ConfigurationError ( format ! (
220+ "Could not parse strict spec (should be boolean) {:?}" ,
221+ v
222+ ) ) . into ( ) )
268223 }
269224 } ;
270225
@@ -281,9 +236,7 @@ pub fn read_configuration_from_str(configuration: &str, filename: &str) -> Resul
281236 None => Vec :: with_capacity ( 0 ) ,
282237 _ => {
283238 println ! ( "Ports is not an array" ) ;
284- return Err (
285- ErrorKind :: ConfigurationError ( String :: from ( "Ports is not an array" ) ) . into ( ) ,
286- ) ;
239+ return Err ( ErrorKind :: ConfigurationError ( String :: from ( "Ports is not an array" ) ) . into ( ) ) ;
287240 }
288241 } ;
289242
@@ -304,8 +257,7 @@ pub fn read_configuration_from_str(configuration: &str, filename: &str) -> Resul
304257/// `filename` should be TOML formatted file.
305258pub fn read_configuration ( filename : & str ) -> Result < NetbricksConfiguration > {
306259 let mut toml_str = String :: new ( ) ;
307- let _ =
308- try!{ File :: open ( filename) . and_then ( |mut f| f. read_to_string ( & mut toml_str) )
309- . chain_err ( || ErrorKind :: ConfigurationError ( String :: from ( "Could not read file" ) ) ) } ;
260+ let _ = try!{ File :: open ( filename) . and_then ( |mut f| f. read_to_string ( & mut toml_str) )
261+ . chain_err ( || ErrorKind :: ConfigurationError ( String :: from ( "Could not read file" ) ) ) } ;
310262 read_configuration_from_str ( & toml_str[ ..] , filename)
311263}
0 commit comments