Skip to content

Commit b52cf05

Browse files
committed
Reformat files
1 parent f8c0f11 commit b52cf05

74 files changed

Lines changed: 395 additions & 512 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis/rustfmt.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
max_width = 120
2-
ideal_width = 120
32
reorder_imports = true
43
report_fixme="Never"

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ rust_fmt () {
233233
RUSTFMT=${BIN_DIR}/cargo-fmt
234234
echo "Checking if ${RUSTFMT} exists (${REQUIRE_RUSTFMT})"
235235
if [ ! -e "${RUSTFMT}" ]; then
236-
${CARGO} install --root ${TOOLS_BASE} rustfmt
236+
${CARGO} install --root ${TOOLS_BASE} rustfmt-nightly
237237
export RUSTFMT=${RUSTFMT}
238238
else
239239
export RUSTFMT=${RUSTFMT}

framework/build.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ fn parse_ld_archive(ar: &Path) -> Vec<String> {
2929
}
3030
}
3131

32-
3332
#[allow(dead_code)]
3433
fn write_external_link(libs: &Vec<String>) {
3534
let out_dir = env::var("OUT_DIR").unwrap();
@@ -42,7 +41,6 @@ fn write_external_link(libs: &Vec<String>) {
4241
}
4342
}
4443

45-
4644
/// Cargo runs main in this file to get some additional settings (e.g., LD_LIBRARY_PATH). It reads the printed output
4745
/// looking for certain variables, see [here](http://doc.crates.io/build-script.html) for documentation.
4846
fn main() {
@@ -74,9 +72,10 @@ fn main() {
7472
"cargo:rustc-link-search=native={}",
7573
native_path.to_str().unwrap()
7674
);
77-
let header_path = Path::new(&cargo_dir).join("src").join("native_include").join(
78-
"dpdk-headers.h",
79-
);
75+
let header_path = Path::new(&cargo_dir)
76+
.join("src")
77+
.join("native_include")
78+
.join("dpdk-headers.h");
8079
let dpdk_include_path = dpdk_build.clone().join("include");
8180
println!("Header path {:?}", header_path.to_str());
8281
let bindings = bindgen::Builder::default()
@@ -87,7 +86,7 @@ fn main() {
8786
.expect("Unable to generate DPDK bindings");
8887
let out_dir = env::var("OUT_DIR").unwrap();
8988
let dpdk_bindings = Path::new(&out_dir).join("dpdk_bindings.rs");
90-
bindings.write_to_file(dpdk_bindings).expect(
91-
"Could not write bindings",
92-
);
89+
bindings
90+
.write_to_file(dpdk_bindings)
91+
.expect("Could not write bindings");
9392
}

framework/src/allocators/cache_aligned.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloc::heap::{Heap, Alloc, Layout};
1+
use alloc::heap::{Alloc, Heap, Layout};
22
use std::fmt;
33
use std::mem::size_of;
44
use std::ops::{Deref, DerefMut};
@@ -43,7 +43,9 @@ impl<T: Sized> CacheAligned<T> {
4343
unsafe {
4444
let alloc = allocate_cache_line(size_of::<T>()) as *mut T;
4545
ptr::write(alloc, src);
46-
CacheAligned { ptr: Unique::new(alloc).unwrap() }
46+
CacheAligned {
47+
ptr: Unique::new(alloc).unwrap(),
48+
}
4749
}
4850
}
4951
}
@@ -56,7 +58,9 @@ where
5658
unsafe {
5759
let alloc = allocate_cache_line(size_of::<T>()) as *mut T;
5860
ptr::copy(self.ptr.as_ptr() as *const T, alloc, 1);
59-
CacheAligned { ptr: Unique::new(alloc).unwrap() }
61+
CacheAligned {
62+
ptr: Unique::new(alloc).unwrap(),
63+
}
6064
}
6165
}
6266
}

framework/src/config/config_reader.rs

Lines changed: 29 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
305258
pub 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
}

framework/src/config/flag_reader.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
extern crate getopts;
2-
use self::getopts::{Options, Matches};
3-
4-
use super::{NetbricksConfiguration, PortConfiguration, read_configuration};
2+
use self::getopts::{Matches, Options};
3+
use super::{read_configuration, NetbricksConfiguration, PortConfiguration};
54
use common::print_error;
65
use std::collections::HashMap;
7-
86
use std::env;
97
use std::process;
108

@@ -36,7 +34,7 @@ pub fn read_matches(matches: &Matches, opts: &Options) -> NetbricksConfiguration
3634
}
3735

3836
if matches.opt_present("dpdk_args") {
39-
print!("dpdk_args: {}", matches.opt_strs("dpdk_args").join(" "));
37+
print!("dpdk_args: {}", matches.opt_strs("dpdk_args").join(" "));
4038
process::exit(0)
4139
};
4240

@@ -56,9 +54,11 @@ pub fn read_matches(matches: &Matches, opts: &Options) -> NetbricksConfiguration
5654

5755
let configuration = if matches.opt_present("m") {
5856
NetbricksConfiguration {
59-
primary_core: matches.opt_str("m").unwrap().parse().expect(
60-
"Could not parse master core",
61-
),
57+
primary_core: matches
58+
.opt_str("m")
59+
.unwrap()
60+
.parse()
61+
.expect("Could not parse master core"),
6262
strict: true,
6363
..configuration
6464
}
@@ -85,19 +85,17 @@ pub fn read_matches(matches: &Matches, opts: &Options) -> NetbricksConfiguration
8585
};
8686

8787
let configuration = if matches.opt_present("c") {
88-
8988
let cores_str = matches.opt_strs("c");
9089

9190
let mut cores: Vec<i32> = cores_str
9291
.iter()
9392
.map(|n: &String| {
94-
n.parse().ok().expect(
95-
&format!("Core cannot be parsed {}", n),
96-
)
93+
n.parse()
94+
.ok()
95+
.expect(&format!("Core cannot be parsed {}", n))
9796
})
9897
.collect();
9998

100-
10199
let cores_for_port = extract_cores_for_port(&matches.opt_strs("p"), &cores);
102100

103101
let ports_to_activate: Vec<_> = cores_for_port.keys().collect();
@@ -125,9 +123,10 @@ pub fn read_matches(matches: &Matches, opts: &Options) -> NetbricksConfiguration
125123
fn extract_cores_for_port(ports: &[String], cores: &[i32]) -> HashMap<String, Vec<i32>> {
126124
let mut cores_for_port = HashMap::<String, Vec<i32>>::new();
127125
for (port, core) in ports.iter().zip(cores.iter()) {
128-
cores_for_port.entry(port.clone()).or_insert(vec![]).push(
129-
*core,
130-
)
126+
cores_for_port
127+
.entry(port.clone())
128+
.or_insert(vec![])
129+
.push(*core)
131130
}
132131
cores_for_port
133132
}

framework/src/config/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ impl fmt::Display for NetbricksConfiguration {
6262
try!(write!(
6363
f,
6464
"Configuration: name: {} mempool size: {} core cache: {} primary core: {}\n Ports:\n",
65-
self.name,
66-
self.pool_size,
67-
self.cache_size,
68-
self.primary_core
65+
self.name, self.pool_size, self.cache_size, self.primary_core
6966
));
7067
for port in &self.ports {
7168
try!(write!(f, "\t{}\n", port))

0 commit comments

Comments
 (0)