Skip to content

Commit

Permalink
unreal_asset: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bananaturtlesandwich committed Apr 10, 2024
1 parent 8d4c03f commit e8154e6
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 71 deletions.
14 changes: 7 additions & 7 deletions unreal_asset/unreal_asset_base/src/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ impl CompressionMethod {
}
}

impl ToString for CompressionMethod {
fn to_string(&self) -> String {
impl std::fmt::Display for CompressionMethod {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CompressionMethod::None => String::from("None"),
CompressionMethod::Zlib => String::from("Zlib"),
CompressionMethod::Gzip => String::from("Gzip"),
CompressionMethod::Lz4 => String::from("LZ4"),
CompressionMethod::Unknown(e) => e.to_string(),
CompressionMethod::None => f.write_str("None"),
CompressionMethod::Zlib => f.write_str("Zlib"),
CompressionMethod::Gzip => f.write_str("Gzip"),
CompressionMethod::Lz4 => f.write_str("LZ4"),
CompressionMethod::Unknown(e) => write!(f, "{e}"),
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions unreal_asset/unreal_asset_base/src/containers/indexed_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,7 @@ where
/// references to it, the Some((index, key, value)) pair is returned,
/// otherwise, None is returned.
pub fn remove_by_index(&mut self, index: usize) -> Option<(usize, K, V)> {
let Some(store_place) = self.index_map.get(&index) else {
return None;
};

self.remove_by_store_place(*store_place)
self.remove_by_store_place(*self.index_map.get(&index)?)
}

/// Removes a value by key
Expand All @@ -711,11 +707,7 @@ where
KeyItem<K>: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
let Some(store_place) = self.key_map.get(key) else {
return None;
};

self.remove_by_store_place(*store_place)
self.remove_by_store_place(*self.key_map.get(key)?)
}

pub fn contains_key(&self, key: &K) -> bool {
Expand Down
5 changes: 0 additions & 5 deletions unreal_asset/unreal_asset_base/src/types/fname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ impl std::cmp::PartialEq<&str> for FName {
}
}

impl std::cmp::PartialEq<String> for FName {
fn eq(&self, other: &String) -> bool {
self == other
}
}
/// A trait that can be implemented for structs that contain an FName
///
/// This trait will be typically used to traverse the whole asset FName tree
Expand Down
6 changes: 3 additions & 3 deletions unreal_asset/unreal_asset_base/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ impl PackageIndexTrait for PackageIndex {
}
}

impl ToString for PackageIndex {
fn to_string(&self) -> String {
self.index.to_string()
impl std::fmt::Display for PackageIndex {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.index)
}
}

Expand Down
8 changes: 2 additions & 6 deletions unreal_asset/unreal_asset_base/src/unversioned/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,9 @@ impl Usmap {
}

// this name is not an actual property name, but an array index
let Ok(_) = property_name.get_content(|name| name.parse::<u32>()) else {
return None;
};
let _ = property_name.get_content(|name| name.parse::<u32>());

let Some(parent) = ancestry.get_parent() else {
return None;
};
let parent = ancestry.get_parent()?;

self.get_property_with_duplication_index(
parent,
Expand Down
66 changes: 33 additions & 33 deletions unreal_asset/unreal_asset_base/src/unversioned/properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,39 @@ pub enum EPropertyType {
Unknown = 0xFF,
}

impl ToString for EPropertyType {
fn to_string(&self) -> String {
match *self {
EPropertyType::ByteProperty => "ByteProperty".to_string(),
EPropertyType::BoolProperty => "BoolProperty".to_string(),
EPropertyType::IntProperty => "IntProperty".to_string(),
EPropertyType::FloatProperty => "FloatProperty".to_string(),
EPropertyType::ObjectProperty => "ObjectProperty".to_string(),
EPropertyType::NameProperty => "NameProperty".to_string(),
EPropertyType::DelegateProperty => "DelegateProperty".to_string(),
EPropertyType::DoubleProperty => "DoubleProperty".to_string(),
EPropertyType::ArrayProperty => "ArrayProperty".to_string(),
EPropertyType::StructProperty => "StructProperty".to_string(),
EPropertyType::StrProperty => "StrProperty".to_string(),
EPropertyType::TextProperty => "TextProperty".to_string(),
EPropertyType::InterfaceProperty => "InterfaceProperty".to_string(),
EPropertyType::MulticastDelegateProperty => "MulticastDelegateProperty".to_string(),
EPropertyType::WeakObjectProperty => "WeakObjectProperty".to_string(),
EPropertyType::LazyObjectProperty => "LazyObjectProperty".to_string(),
EPropertyType::AssetObjectProperty => "AssetObjectProperty".to_string(),
EPropertyType::SoftObjectProperty => "SoftObjectProperty".to_string(),
EPropertyType::UInt64Property => "UInt64Property".to_string(),
EPropertyType::UInt32Property => "UInt32Property".to_string(),
EPropertyType::UInt16Property => "UInt16Property".to_string(),
EPropertyType::Int64Property => "Int64Property".to_string(),
EPropertyType::Int16Property => "Int16Property".to_string(),
EPropertyType::Int8Property => "Int8Property".to_string(),
EPropertyType::MapProperty => "MapProperty".to_string(),
EPropertyType::SetProperty => "SetProperty".to_string(),
EPropertyType::EnumProperty => "EnumProperty".to_string(),
EPropertyType::FieldPathProperty => "FieldPathProperty".to_string(),
EPropertyType::Unknown => "Unknown".to_string(),
}
impl std::fmt::Display for EPropertyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match *self {
EPropertyType::ByteProperty => "ByteProperty",
EPropertyType::BoolProperty => "BoolProperty",
EPropertyType::IntProperty => "IntProperty",
EPropertyType::FloatProperty => "FloatProperty",
EPropertyType::ObjectProperty => "ObjectProperty",
EPropertyType::NameProperty => "NameProperty",
EPropertyType::DelegateProperty => "DelegateProperty",
EPropertyType::DoubleProperty => "DoubleProperty",
EPropertyType::ArrayProperty => "ArrayProperty",
EPropertyType::StructProperty => "StructProperty",
EPropertyType::StrProperty => "StrProperty",
EPropertyType::TextProperty => "TextProperty",
EPropertyType::InterfaceProperty => "InterfaceProperty",
EPropertyType::MulticastDelegateProperty => "MulticastDelegateProperty",
EPropertyType::WeakObjectProperty => "WeakObjectProperty",
EPropertyType::LazyObjectProperty => "LazyObjectProperty",
EPropertyType::AssetObjectProperty => "AssetObjectProperty",
EPropertyType::SoftObjectProperty => "SoftObjectProperty",
EPropertyType::UInt64Property => "UInt64Property",
EPropertyType::UInt32Property => "UInt32Property",
EPropertyType::UInt16Property => "UInt16Property",
EPropertyType::Int64Property => "Int64Property",
EPropertyType::Int16Property => "Int16Property",
EPropertyType::Int8Property => "Int8Property",
EPropertyType::MapProperty => "MapProperty",
EPropertyType::SetProperty => "SetProperty",
EPropertyType::EnumProperty => "EnumProperty",
EPropertyType::FieldPathProperty => "FieldPathProperty",
EPropertyType::Unknown => "Unknown",
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion unreal_asset/unreal_asset_properties/src/enum_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl PropertyTrait for EnumProperty {
Some(value) => info
.iter()
.enumerate()
.find(|(_, e)| value == *e)
.find(|(_, e)| value == e.as_str())
.map(|(index, _)| index as u8)
.ok_or_else(|| {
Error::invalid_file(
Expand Down
12 changes: 6 additions & 6 deletions unreal_asset/unreal_asset_registry/src/objects/depends_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl DependsNode {
/// Read `DependsNode` dependencies
fn read_dependencies<Reader: ArchiveReader<impl PackageIndexTrait>>(
asset: &mut Reader,
preallocated_depends_node_buffer: &Vec<DependsNode>,
preallocated_depends_node_buffer: &[DependsNode],
flag_set_width: i32,
) -> Result<LoadedDependencyNodes, Error> {
let mut sort_indexes = Vec::new();
Expand Down Expand Up @@ -244,8 +244,8 @@ impl DependsNode {
writer: &mut Writer,
flag_set_width: i32,
flags: &BitVec<u32, Lsb0>,
hard_dependencies: &Vec<DependsNode>,
soft_dependencies: &Vec<DependsNode>,
hard_dependencies: &[DependsNode],
soft_dependencies: &[DependsNode],
) -> Result<(), Error> {
let dependencies_length = hard_dependencies.len() as i32 + soft_dependencies.len() as i32;
let mut out_flag_bits = BitVec::<u32, Lsb0>::new();
Expand Down Expand Up @@ -301,7 +301,7 @@ impl DependsNode {
/// Read `DependsNode` dependencies without flags
fn read_dependencies_no_flags<Reader: ArchiveReader<impl PackageIndexTrait>>(
asset: &mut Reader,
preallocated_depends_node_buffer: &Vec<DependsNode>,
preallocated_depends_node_buffer: &[DependsNode],
) -> Result<Vec<DependsNode>, Error> {
let mut pointer_dependencies = Vec::new();
let in_dependencies = asset.read_array(|asset: &mut Reader| Ok(asset.read_i32::<LE>()?))?;
Expand Down Expand Up @@ -341,7 +341,7 @@ impl DependsNode {
/// Write `DependsNode` dependencies without flags
fn write_dependencies_no_flags<Writer: ArchiveWriter<impl PackageIndexTrait>>(
writer: &mut Writer,
dependencies: &Vec<DependsNode>,
dependencies: &[DependsNode],
) -> Result<(), Error> {
writer.write_i32::<LE>(dependencies.len() as i32)?;
for dependency in dependencies {
Expand Down Expand Up @@ -371,7 +371,7 @@ impl DependsNode {
pub fn load_dependencies<Reader: ArchiveReader<impl PackageIndexTrait>>(
&mut self,
asset: &mut Reader,
preallocated_depends_node_buffer: &Vec<DependsNode>,
preallocated_depends_node_buffer: &[DependsNode],
) -> Result<(), Error> {
let identifier = AssetIdentifier::new(asset)?;

Expand Down

0 comments on commit e8154e6

Please sign in to comment.