Skip to content

Commit

Permalink
Update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanademovic committed May 13, 2017
1 parent ceb3d61 commit 98ed1e5
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 129 deletions.
6 changes: 1 addition & 5 deletions src/api/naming/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ impl Mapper {
pub fn translate(&self, keys: &[String]) -> Option<Slice> {
match keys.split_first() {
None => self.value.as_ref().map(|v| v.slice()),
Some((key, child_keys)) => {
self.children
.get(key)
.and_then(|v| v.translate(child_keys))
}
Some((key, child_keys)) => self.children.get(key).and_then(|v| v.translate(child_keys)),
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/api/naming/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ mod tests {
assert_eq!(vec![String::from("f1_aA"),
String::from("Ba02"),
String::from("Xx")],
r.resolve("/f1_aA/Ba02/Xx")
.expect(FAILED_TO_RESOLVE)
.get());
r.resolve("/f1_aA/Ba02/Xx").expect(FAILED_TO_RESOLVE).get());
}

#[test]
Expand All @@ -112,9 +110,7 @@ mod tests {
String::from("f1_aA"),
String::from("Ba02"),
String::from("Xx")],
r.resolve("f1_aA/Ba02/Xx")
.expect(FAILED_TO_RESOLVE)
.get());
r.resolve("f1_aA/Ba02/Xx").expect(FAILED_TO_RESOLVE).get());
}

#[test]
Expand All @@ -137,9 +133,7 @@ mod tests {
String::from("f1_aA"),
String::from("Ba02"),
String::from("Xx")],
r.resolve("~f1_aA/Ba02/Xx")
.expect(FAILED_TO_RESOLVE)
.get());
r.resolve("~f1_aA/Ba02/Xx").expect(FAILED_TO_RESOLVE).get());
}

#[test]
Expand Down
9 changes: 2 additions & 7 deletions src/api/naming/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ mod tests {
assert_eq!(vec![String::from("foo")],
"/foo".parse::<Buffer>().expect(FAILED_TO_HANDLE).get());
assert_eq!(vec![String::from("foo"), String::from("bar")],
"/foo/bar"
.parse::<Buffer>()
.expect(FAILED_TO_HANDLE)
.get());
"/foo/bar".parse::<Buffer>().expect(FAILED_TO_HANDLE).get());
assert_eq!(vec![String::from("f1_aA"),
String::from("Ba02"),
String::from("Xx")],
Expand All @@ -178,9 +175,7 @@ mod tests {
format!("{}", "/foo/bar".parse::<Buffer>().expect(FAILED_TO_HANDLE)));
assert_eq!("/f1_aA/Ba02/Xx",
format!("{}",
"/f1_aA/Ba02/Xx"
.parse::<Buffer>()
.expect(FAILED_TO_HANDLE)));
"/f1_aA/Ba02/Xx".parse::<Buffer>().expect(FAILED_TO_HANDLE)));
}

#[test]
Expand Down
8 changes: 2 additions & 6 deletions src/api/ros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ impl Ros {
}

fn map(&mut self, source: &str, destination: &str) -> Result<()> {
self.resolver
.map(source, destination)
.map_err(|v| v.into())
self.resolver.map(source, destination).map_err(|v| v.into())
}

pub fn uri(&self) -> &str {
Expand Down Expand Up @@ -173,9 +171,7 @@ impl<'a> Parameter<'a> {
}

pub fn set<T: Encodable>(&self, value: &T) -> MasterResult<()> {
self.master
.set_param::<T>(&self.name, value)
.and(Ok(()))
self.master.set_param::<T>(&self.name, value).and(Ok(()))
}

pub fn delete(&self) -> MasterResult<()> {
Expand Down
5 changes: 1 addition & 4 deletions src/api/slave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ impl Slave {
}

pub fn remove_service(&mut self, service: &str) {
self.services
.lock()
.expect(FAILED_TO_LOCK)
.remove(service);
self.services.lock().expect(FAILED_TO_LOCK).remove(service);
}

pub fn add_publication<T>(&mut self,
Expand Down
10 changes: 2 additions & 8 deletions src/api/slavehandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ impl SlaveHandler {
return Ok(Err("Empty strings given".into()));
}
info!("Server is shutting down because: {}", message);
if let Err(..) = self.shutdown_signal
.lock()
.expect(FAILED_TO_LOCK)
.send(()) {
if let Err(..) = self.shutdown_signal.lock().expect(FAILED_TO_LOCK).send(()) {
bail!("Slave API is down already");
}
Ok(Ok(0))
Expand Down Expand Up @@ -203,10 +200,7 @@ impl SlaveHandler {
Some(v) => v.value(),
None => return Ok(Err("Missing parameter".into())),
};
let (ip, port) = match self.publications
.lock()
.expect(FAILED_TO_LOCK)
.get(&topic) {
let (ip, port) = match self.publications.lock().expect(FAILED_TO_LOCK).get(&topic) {
Some(publisher) => (self.hostname.clone(), publisher.port as i32),
None => {
return Ok(Err("Requested topic not published by node".into()));
Expand Down
8 changes: 2 additions & 6 deletions src/build_tools/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,13 @@ mod tests {
.get(&("geometry_msgs".into(), "Pose".into()))
.unwrap(),
"e45d45a5a1ce597b249e23fb30fc871f".to_owned());
assert_eq!(*hashes
.get(&("std_msgs".into(), "Header".into()))
.unwrap(),
assert_eq!(*hashes.get(&("std_msgs".into(), "Header".into())).unwrap(),
"2176decaecbce78abc3b96ef049fabed".to_owned());
assert_eq!(*hashes
.get(&("geometry_msgs".into(), "PoseStamped".into()))
.unwrap(),
"d3812c3cbc69362b77dc0b19b345f8f5".to_owned());
assert_eq!(*hashes
.get(&("sensor_msgs".into(), "Imu".into()))
.unwrap(),
assert_eq!(*hashes.get(&("sensor_msgs".into(), "Imu".into())).unwrap(),
"6a62c6daae103f4ff57a132d6f95cec2".to_owned());
}

Expand Down
5 changes: 1 addition & 4 deletions src/build_tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,5 @@ pub fn depend_on_messages(messages: &[&str]) {
}

fn append_share_folder(path: &str) -> Option<String> {
Path::new(path)
.join("share")
.to_str()
.map(|v| v.to_owned())
Path::new(path).join("share").to_str().map(|v| v.to_owned())
}
31 changes: 14 additions & 17 deletions src/build_tools/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ fn match_line(data: &str) -> Option<Result<FieldInfo>> {
#[inline]
fn strip_useless<'a>(data: &'a str) -> Result<&'a str> {
Ok(data.splitn(2, '#')
.next()
.ok_or_else(|| {
format!("Somehow splitting a line resulted in 0 parts?! Happened here: {}",
data)
})?
.trim())
.next()
.ok_or_else(|| {
format!("Somehow splitting a line resulted in 0 parts?! Happened here: {}",
data)
})?
.trim())
}

#[inline]
Expand Down Expand Up @@ -332,13 +332,13 @@ impl FieldInfo {
DataType::LocalStruct(..) => return None,
DataType::RemoteStruct(..) => return None,
_ => {
let datatype = self.datatype.rust_type();
format!("const {}: {} = {} as {};",
self.name,
datatype,
value,
datatype)
}
let datatype = self.datatype.rust_type();
format!("const {}: {} = {} as {};",
self.name,
datatype,
value,
datatype)
}
})
}

Expand Down Expand Up @@ -437,10 +437,7 @@ impl DataType {
.as_str()
}
DataType::RemoteStruct(ref pkg, ref name) => {
hashes
.get(&(pkg.clone(), name.clone()))
.ok_or(())?
.as_str()
hashes.get(&(pkg.clone(), name.clone())).ok_or(())?.as_str()
}
}
.into())
Expand Down
10 changes: 2 additions & 8 deletions src/rosxmlrpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ impl Client {
request.encoder.write_request(&request.name, &mut body)?;

let body = String::from_utf8(body)?;
let res = self.http_client
.post(&self.server_uri)
.body(&body)
.send()?;
let res = self.http_client.post(&self.server_uri).body(&body).send()?;

let mut res = serde::Decoder::new_response(res)?;
match res.pop() {
Expand All @@ -40,10 +37,7 @@ impl Client {
request.encoder.write_request(&request.name, &mut body)?;

let body = String::from_utf8(body)?;
let res = self.http_client
.post(&self.server_uri)
.body(&body)
.send()?;
let res = self.http_client.post(&self.server_uri).body(&body).send()?;

let mut res = serde::Decoder::new_response(res)?;
let mut value = match res.pop() {
Expand Down
17 changes: 2 additions & 15 deletions src/rosxmlrpc/serde/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,13 @@ impl Decoder {
pub fn new_request<T: std::io::Read>(body: T) -> Result<(String, Vec<Decoder>)> {
value::XmlRpcRequest::new(body)
.chain_err(|| ErrorKind::XmlRpcReading("request".into()))
.map(|value| {
(value.method,
value
.parameters
.into_iter()
.map(Decoder::new)
.collect())
})
.map(|value| (value.method, value.parameters.into_iter().map(Decoder::new).collect()))
}

pub fn new_response<T: std::io::Read>(body: T) -> Result<Vec<Decoder>> {
value::XmlRpcResponse::new(body)
.chain_err(|| ErrorKind::XmlRpcReading("response".into()))
.map(|value| {
value
.parameters
.into_iter()
.map(Decoder::new)
.collect()
})
.map(|value| value.parameters.into_iter().map(Decoder::new).collect())
}

pub fn value(self) -> value::XmlRpcValue {
Expand Down
36 changes: 9 additions & 27 deletions src/rosxmlrpc/serde/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ mod tests {
String::from("Hello")
.encode(&mut encoder)
.expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand Down Expand Up @@ -312,9 +310,7 @@ mod tests {
String::from("Friend")
.encode(&mut encoder)
.expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand All @@ -339,9 +335,7 @@ mod tests {
43i32.encode(&mut encoder).expect(FAILED_TO_ENCODE);
27i32.encode(&mut encoder).expect(FAILED_TO_ENCODE);
12i32.encode(&mut encoder).expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand All @@ -366,9 +360,7 @@ mod tests {
33.5f64.encode(&mut encoder).expect(FAILED_TO_ENCODE);
11.25f64.encode(&mut encoder).expect(FAILED_TO_ENCODE);
77.125f64.encode(&mut encoder).expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand All @@ -392,9 +384,7 @@ mod tests {
let mut encoder = Encoder::new();
true.encode(&mut encoder).expect(FAILED_TO_ENCODE);
false.encode(&mut encoder).expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand All @@ -416,9 +406,7 @@ mod tests {
vec![1i32, 2, 3, 4, 5]
.encode(&mut encoder)
.expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand Down Expand Up @@ -446,9 +434,7 @@ mod tests {
ExampleTuple(5, 0.5, String::from("abc"), false)
.encode(&mut encoder)
.expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand Down Expand Up @@ -492,9 +478,7 @@ mod tests {
}
.encode(&mut encoder)
.expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand Down Expand Up @@ -534,9 +518,7 @@ mod tests {
}
.encode(&mut encoder)
.expect(FAILED_TO_ENCODE);
encoder
.write_response(&mut data)
.expect(FAILED_TO_ENCODE);
encoder.write_response(&mut data).expect(FAILED_TO_ENCODE);
assert_eq!(concat!(r#"<?xml version="1.0"?>"#,
r#"<methodResponse>"#,
r#"<params>"#,
Expand Down
Loading

0 comments on commit 98ed1e5

Please sign in to comment.