Skip to content

Commit

Permalink
fix clippy warnings and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ScanMountGoat committed Sep 1, 2021
1 parent 084a449 commit 0da4b24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions xmb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fn main() {
// Ex: model.xmb.xml -> model.xmb.xmb.
let output = matches
.value_of("output")
.map(|o| PathBuf::from(o))
.unwrap_or(PathBuf::from(input).with_extension("xmb"));
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from(input).with_extension("xmb"));

match output.extension().unwrap().to_str().unwrap() {
"xmb" => xmb.write_to_file(output).unwrap(),
Expand All @@ -62,8 +62,8 @@ fn main() {
// Ex: model.xmb -> model.xmb.xml.
let output = matches
.value_of("output")
.map(|o| PathBuf::from(o))
.unwrap_or(PathBuf::from(input.to_string() + ".xml"));
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from(input.to_string() + ".xml"));

match output.extension().unwrap().to_str().unwrap() {
"xmb" => xmb.write_to_file(output).unwrap(),
Expand Down
9 changes: 4 additions & 5 deletions xmb_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl From<&XmbFile> for Xmb {
attribute_count: attributes.len() as u32,
string_count: string_offsets.len() as u32,
mapped_entry_count: mapped_entries.len() as u32,
string_offsets: Ptr32::new(string_offsets.values().map(|v| *v).collect()),
string_offsets: Ptr32::new(string_offsets.values().copied().collect()),
entries: Ptr32::new(entries),
attributes: Ptr32::new(attributes),
mapped_entries: Ptr32::new(mapped_entries),
Expand Down Expand Up @@ -285,7 +285,6 @@ fn calculate_unk1_leaf(
// TODO: It might be simpler to just match on find_next_sibling for parent.
match find_parent(parent, flattened_temp_entries) {
Some(grand_parent) => {

let next_sibling = find_next_sibling(parent, flattened_temp_entries);

// TODO: There's a case for some lod.xmb files where this can return -1?
Expand Down Expand Up @@ -314,7 +313,7 @@ fn calculate_unk1_leaf(
None => {
// It's possible for only some of a node's children to be leaves (no children).
// This case comes up in some model.xmb files.
let next_sibling = find_next_sibling_with_children(entry, &flattened_temp_entries);
let next_sibling = find_next_sibling_with_children(entry, flattened_temp_entries);
next_sibling.map(|s| s.index)
}
}
Expand Down Expand Up @@ -347,7 +346,7 @@ fn find_next_sibling<'a>(
.position(|s| s.index == entry.index)
.unwrap();

siblings.get(sibling_index + 1).map(|e| *e)
siblings.get(sibling_index + 1).copied()
}

fn find_next_sibling_with_children<'a>(
Expand Down Expand Up @@ -444,7 +443,7 @@ fn xmb_file_from_xmb(xmb_data: &Xmb) -> XmbFile {
.iter()
.enumerate()
.filter(|(_, e)| e.parent_index == -1)
.map(|(i, e)| create_children_recursive(&xmb_data, e, i as i16))
.map(|(i, e)| create_children_recursive(xmb_data, e, i as i16))
.collect();

XmbFile { entries: roots }
Expand Down
4 changes: 2 additions & 2 deletions xmb_lib/src/xmb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ impl BinRead for StringBuffer {
// The names buffer has a specified string count.
let mut buffer_reader = Cursor::new(buffer);
loop {
let relative_offset = (&mut buffer_reader).stream_position()?;
if relative_offset as usize >= (&mut buffer_reader).get_ref().len() {
let relative_offset = buffer_reader.stream_position()?;
if relative_offset as usize >= buffer_reader.get_ref().len() {
break;
}
let byte_result: Result<Vec<u8>, _> = (&mut buffer_reader)
Expand Down

0 comments on commit 0da4b24

Please sign in to comment.