Skip to content

Commit 0f3ee87

Browse files
committed
Run cargo fmt
1 parent 07d3337 commit 0f3ee87

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

src/lib.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,9 @@ pub fn get_jvm_dyn_lib_file_name() -> &'static str {
162162
/// If `JAVA_HOME` is not defined, the function tries to locate it using the `java` executable.
163163
pub fn locate_java_home() -> errors::Result<String> {
164164
match &env::var("JAVA_HOME") {
165-
Ok(s) if s.is_empty() => {
166-
do_locate_java_home()
167-
}
165+
Ok(s) if s.is_empty() => do_locate_java_home(),
168166
Ok(java_home_env_var) => Ok(java_home_env_var.clone()),
169-
Err(_) => {
170-
do_locate_java_home()
171-
}
167+
Err(_) => do_locate_java_home(),
172168
}
173169
}
174170

@@ -189,25 +185,31 @@ fn do_locate_java_home() -> errors::Result<String> {
189185
}
190186

191187
let output = command.output().map_err(|error| {
192-
let message = format!("Command '{}' is not found in the system PATH ({})", command_str, error);
188+
let message = format!(
189+
"Command '{}' is not found in the system PATH ({})",
190+
command_str, error
191+
);
193192
errors::JavaLocatorError::new(&message)
194193
})?;
195-
let java_exec_path = String::from_utf8(output.stdout)
196-
.map(|jp| {
197-
let mut lines: Vec<&str> = jp.lines().collect();
198-
if lines.len() > 1 {
199-
println!("WARNING: java_locator found {} possible java locations: {}. Using the last one.",
200-
lines.len(),
201-
lines.join(", "));
202-
lines.remove(lines.len() - 1).to_string()
203-
} else {
204-
jp
205-
}
206-
})?;
194+
let java_exec_path = String::from_utf8(output.stdout).map(|jp| {
195+
let mut lines: Vec<&str> = jp.lines().collect();
196+
if lines.len() > 1 {
197+
println!(
198+
"WARNING: java_locator found {} possible java locations: {}. Using the last one.",
199+
lines.len(),
200+
lines.join(", ")
201+
);
202+
lines.remove(lines.len() - 1).to_string()
203+
} else {
204+
jp
205+
}
206+
})?;
207207

208208
// Return early in case that the java executable is not found
209209
if java_exec_path.is_empty() {
210-
Err(errors::JavaLocatorError::new("Java is not installed or not added in the system PATH"))?
210+
Err(errors::JavaLocatorError::new(
211+
"Java is not installed or not added in the system PATH",
212+
))?
211213
}
212214

213215
let mut test_path = PathBuf::from(java_exec_path.trim());
@@ -230,17 +232,16 @@ fn do_locate_java_home() -> errors::Result<String> {
230232

231233
match test_path.to_str() {
232234
Some(s) => Ok(String::from(s)),
233-
None => Err(errors::JavaLocatorError::new(&format!("Could not convert path {:?} to String", test_path))),
235+
None => Err(errors::JavaLocatorError::new(&format!(
236+
"Could not convert path {:?} to String",
237+
test_path
238+
))),
234239
}
235240
}
236241

237242
/// Returns the path that contains the `libjvm.so` (or `jvm.dll` in windows).
238243
pub fn locate_jvm_dyn_library() -> errors::Result<String> {
239-
let jvm_dyn_lib_file_name = if is_windows() {
240-
"jvm.dll"
241-
} else {
242-
"libjvm.*"
243-
};
244+
let jvm_dyn_lib_file_name = if is_windows() { "jvm.dll" } else { "libjvm.*" };
244245

245246
locate_file(jvm_dyn_lib_file_name)
246247
}
@@ -265,7 +266,10 @@ pub fn locate_file(file_name: &str) -> errors::Result<String> {
265266
.collect();
266267

267268
if paths_vec.is_empty() {
268-
Err(errors::JavaLocatorError::new(&format!("Could not find the {} library in any subdirectory of {}", file_name, java_home)))
269+
Err(errors::JavaLocatorError::new(&format!(
270+
"Could not find the {} library in any subdirectory of {}",
271+
file_name, java_home
272+
)))
269273
} else {
270274
Ok(paths_vec[0].clone())
271275
}
@@ -278,11 +282,14 @@ mod unit_tests {
278282
#[test]
279283
fn locate_java_home_test() {
280284
println!("locate_java_home: {}", locate_java_home().unwrap());
281-
println!("locate_jvm_dyn_library: {}", locate_jvm_dyn_library().unwrap());
285+
println!(
286+
"locate_jvm_dyn_library: {}",
287+
locate_jvm_dyn_library().unwrap()
288+
);
282289
}
283290

284291
#[test]
285292
fn locate_java_from_exec_test() {
286293
println!("do_locate_java_home: {}", do_locate_java_home().unwrap());
287294
}
288-
}
295+
}

0 commit comments

Comments
 (0)