mirror of
https://github.com/widberg/bff
synced 2026-08-23 14:26:03 -04:00
Fix clippy lints
This commit is contained in:
parent
4ad81db060
commit
d5a120c304
23 changed files with 52 additions and 52 deletions
|
|
@ -11,6 +11,8 @@ edition = "2024"
|
|||
rust-version = "1.88.0"
|
||||
|
||||
[workspace.lints.clippy]
|
||||
allow_attributes = "warn"
|
||||
assigning_clones = "warn"
|
||||
bool_to_int_with_if = "warn"
|
||||
branches_sharing_code = "warn"
|
||||
comparison_chain = "warn"
|
||||
|
|
@ -20,6 +22,7 @@ flat_map_option = "warn"
|
|||
if_then_some_else_none = "warn"
|
||||
implicit_clone = "warn"
|
||||
manual_midpoint = "warn"
|
||||
missing_const_for_fn = "warn"
|
||||
non_std_lazy_statics = "warn"
|
||||
precedence_bits = "warn"
|
||||
redundant_test_prefix = "warn"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use bff::bigfile::platforms::Platform;
|
|||
use bff::bigfile::resource::{BffClass, Resource};
|
||||
use bff::bigfile::versions::Version;
|
||||
use bff::names::{NameContext, NameType};
|
||||
use bff::traits::{Artifact, Import, IntoResource};
|
||||
use bff::traits::{Artifact, Import, ToResource};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
|
||||
use crate::error::BffCliResult;
|
||||
|
|
@ -32,7 +32,6 @@ fn validate_version_override_name_type(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn create(
|
||||
directory: &Path,
|
||||
bigfile_path: &Path,
|
||||
|
|
@ -128,7 +127,7 @@ pub fn create(
|
|||
let resource: Resource =
|
||||
bff_class
|
||||
.class
|
||||
.into_resource(version.clone(), platform, &name_context)?;
|
||||
.to_resource(version.clone(), platform, &name_context)?;
|
||||
|
||||
if resources.contains_key(&resource.name) {
|
||||
return Err(crate::error::BffCliError::DuplicateResource {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use bff::bigfile::platforms::Platform;
|
|||
use bff::bigfile::resource::{BffClass, Resource};
|
||||
use bff::bigfile::versions::Version;
|
||||
use bff::names::{NameContext, NameType};
|
||||
use bff::traits::{Artifact, Import, IntoResource};
|
||||
use bff::traits::{Artifact, Import, ToResource};
|
||||
|
||||
use crate::error::BffCliResult;
|
||||
use crate::extract::write_names;
|
||||
|
|
@ -92,7 +92,7 @@ pub fn create_resource(
|
|||
let resource: Resource =
|
||||
bff_class
|
||||
.class
|
||||
.into_resource(version.clone(), platform, &name_context)?;
|
||||
.to_resource(version.clone(), platform, &name_context)?;
|
||||
|
||||
let mut resource_writer = BufWriter::new(File::create(resource_path)?);
|
||||
Resource::dump_bff_resource(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ platforms! {
|
|||
}
|
||||
|
||||
impl Platform {
|
||||
pub fn size_on_disk(&self) -> u16 {
|
||||
pub const fn size_on_disk(&self) -> u16 {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ impl BffResourceHeader {
|
|||
header.name_type()
|
||||
}
|
||||
|
||||
fn data_padded_size_on_disk(&self) -> u16 {
|
||||
const fn data_padded_size_on_disk(&self) -> u16 {
|
||||
let non_data_size = 4 + 2;
|
||||
let total_unpadded_size =
|
||||
non_data_size + self.platform.size_on_disk() + self.version.size_on_disk();
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ pub struct PoolResource {
|
|||
pub resource: Resource,
|
||||
}
|
||||
|
||||
pub fn calculate_padded_pool_header_size(
|
||||
pub const fn calculate_padded_pool_header_size(
|
||||
object_names_count: usize,
|
||||
resource_descriptions_count: usize,
|
||||
reference_records_count: usize,
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ pub struct PoolHeader {
|
|||
_reference_records_sentinel: ReferenceRecord,
|
||||
}
|
||||
|
||||
pub fn calculate_padded_pool_header_size(
|
||||
pub const fn calculate_padded_pool_header_size(
|
||||
resource_descriptions_indices_size: usize,
|
||||
resource_descriptions_size: usize,
|
||||
reference_records_size: usize,
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ pub enum Version {
|
|||
}
|
||||
|
||||
impl Version {
|
||||
pub fn size_on_disk(&self) -> u16 {
|
||||
pub const fn size_on_disk(&self) -> u16 {
|
||||
1 + match self {
|
||||
Self::Asobo(_, _, _, _) => 2 * 4,
|
||||
Self::AsoboLegacy(_, _) => 2 * 2,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ impl Import for BitmapV1_06_63_02PC {
|
|||
else {
|
||||
return Err(Error::ImportBadArtifact);
|
||||
};
|
||||
self.body.data = data.clone();
|
||||
self.body.data.clone_from(data);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ impl Import for BitmapV1_291_03_06PC {
|
|||
else {
|
||||
return Err(Error::ImportBadArtifact);
|
||||
};
|
||||
self.body.data = data.clone();
|
||||
self.body.data.clone_from(data);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ impl Export for BitmapV1_381_67_09PC {
|
|||
caps2,
|
||||
})
|
||||
.unwrap();
|
||||
dds.data = self.body.data.clone();
|
||||
dds.data.clone_from(&self.body.data);
|
||||
let mut dds_writer = Cursor::new(Vec::new());
|
||||
dds.write(&mut dds_writer).unwrap();
|
||||
Ok(HashMap::from([(
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ pub enum Vertices {
|
|||
}
|
||||
|
||||
impl Vertices {
|
||||
pub fn len(&self) -> usize {
|
||||
pub const fn len(&self) -> usize {
|
||||
match self {
|
||||
Self::LayoutPosition(layout_positions) => layout_positions.len(),
|
||||
Self::LayoutPositionUV(layout_position_uvs) => layout_position_uvs.len(),
|
||||
|
|
@ -139,7 +139,7 @@ impl Vertices {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
match self {
|
||||
Self::LayoutPosition(layout_positions) => layout_positions.is_empty(),
|
||||
Self::LayoutPositionUV(layout_position_uvs) => layout_position_uvs.is_empty(),
|
||||
|
|
@ -150,7 +150,7 @@ impl Vertices {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn layout(&self) -> usize {
|
||||
pub const fn layout(&self) -> usize {
|
||||
match self {
|
||||
Self::LayoutPosition(_) => LayoutPosition::SIZE,
|
||||
Self::LayoutPositionUV(_) => LayoutPositionUV::SIZE,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::bigfile::resource::Resource;
|
|||
use crate::bigfile::resource::ResourceData::{Data, SplitData};
|
||||
use crate::bigfile::versions::Version;
|
||||
use crate::names::{Name, NameContext};
|
||||
use crate::traits::{FromResource, IntoResource};
|
||||
use crate::traits::{FromResource, ToResource};
|
||||
use crate::{BffError, BffResult};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema, ReferencedNames)]
|
||||
|
|
@ -90,14 +90,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<LinkHeaderType, BodyType> IntoResource for TrivialClass<LinkHeaderType, BodyType>
|
||||
impl<LinkHeaderType, BodyType> ToResource for TrivialClass<LinkHeaderType, BodyType>
|
||||
where
|
||||
for<'a> LinkHeaderType: BinWrite + 'a,
|
||||
for<'a> <LinkHeaderType as BinWrite>::Args<'a>: Default,
|
||||
for<'a> BodyType: BinWrite + 'a,
|
||||
for<'a> <BodyType as BinWrite>::Args<'a>: Default,
|
||||
{
|
||||
fn into_resource(
|
||||
fn to_resource(
|
||||
&self,
|
||||
_version: Version,
|
||||
platform: Platform,
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ mod math;
|
|||
mod option;
|
||||
mod strings;
|
||||
|
||||
pub fn calculate_padding(position: usize, alignment: usize) -> usize {
|
||||
pub const fn calculate_padding(position: usize, alignment: usize) -> usize {
|
||||
position.next_multiple_of(alignment) - position
|
||||
}
|
||||
|
||||
pub fn calculated_padded(position: usize, alignment: usize) -> usize {
|
||||
pub const fn calculated_padded(position: usize, alignment: usize) -> usize {
|
||||
position.next_multiple_of(alignment)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ struct Packet {
|
|||
}
|
||||
|
||||
impl Packet {
|
||||
fn with_match_length(match_length: i32) -> Self {
|
||||
const fn with_match_length(match_length: i32) -> Self {
|
||||
Self {
|
||||
match_length,
|
||||
total_length: 0,
|
||||
|
|
@ -153,7 +153,7 @@ impl Packet {
|
|||
}
|
||||
}
|
||||
|
||||
fn reset_total_length(&mut self) {
|
||||
const fn reset_total_length(&mut self) {
|
||||
self.total_length = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
macro_rules! bigfiles {
|
||||
($($pattern:pat => $bigfile:ident),* $(,)?) => {
|
||||
impl BigFile {
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub fn read_platform<R: std::io::Read + std::io::Seek>(
|
||||
reader: &mut R,
|
||||
platform: crate::bigfile::platforms::Platform,
|
||||
|
|
@ -35,7 +35,7 @@ macro_rules! bigfiles {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub fn write<W: std::io::Write + std::io::Seek>(
|
||||
&self,
|
||||
writer: &mut W,
|
||||
|
|
@ -78,7 +78,7 @@ macro_rules! bigfiles {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub fn dump_resource<W: std::io::Write + std::io::Seek>(
|
||||
&self,
|
||||
resource: &crate::bigfile::resource::Resource,
|
||||
|
|
@ -112,7 +112,7 @@ macro_rules! bigfiles {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub fn read_resource<R: std::io::Read + std::io::Seek>(
|
||||
&self,
|
||||
reader: &mut R,
|
||||
|
|
@ -145,7 +145,7 @@ macro_rules! bigfiles {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub fn read_bff_resource<R: std::io::Read + std::io::Seek>(
|
||||
&self,
|
||||
reader: &mut R,
|
||||
|
|
@ -179,7 +179,7 @@ macro_rules! bigfiles {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
impl crate::bigfile::resource::Resource {
|
||||
pub fn dump_resource<W: std::io::Write + std::io::Seek>(
|
||||
&self,
|
||||
|
|
@ -214,7 +214,7 @@ macro_rules! bigfiles {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub fn dump_bff_resource<W: std::io::Write + std::io::Seek>(
|
||||
&self,
|
||||
writer: &mut W,
|
||||
|
|
@ -255,7 +255,7 @@ macro_rules! bigfiles {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub fn read_resource<R: std::io::Read + std::io::Seek>(
|
||||
reader: &mut R,
|
||||
platform: crate::bigfile::platforms::Platform,
|
||||
|
|
@ -287,7 +287,7 @@ macro_rules! bigfiles {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[expect(unused_imports)]
|
||||
pub fn read_bff_resource<R: std::io::Read + std::io::Seek>(
|
||||
reader: &mut R,
|
||||
name_context: &crate::names::NameContext,
|
||||
|
|
|
|||
|
|
@ -120,22 +120,22 @@ macro_rules! classes {
|
|||
};
|
||||
|
||||
(@emit_try_into_resource $($class:ident)*) => {
|
||||
impl crate::traits::IntoResource for Class {
|
||||
fn into_resource(
|
||||
impl crate::traits::ToResource for Class {
|
||||
fn to_resource(
|
||||
&self,
|
||||
version: crate::bigfile::versions::Version,
|
||||
platform: crate::bigfile::platforms::Platform,
|
||||
name_context: &crate::names::NameContext,
|
||||
) -> crate::BffResult<crate::bigfile::resource::Resource> {
|
||||
match self {
|
||||
$(Class::$class(class) => <$crate::macros::classes::classes!(@class_ty $class) as crate::traits::IntoResource>::into_resource(class, version, platform, name_context),)*
|
||||
$(Class::$class(class) => <$crate::macros::classes::classes!(@class_ty $class) as crate::traits::ToResource>::to_resource(class, version, platform, name_context),)*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(@emit_class_names_fn $($class:ident)*) => {
|
||||
pub fn class_base_names() -> &'static[&'static str] {
|
||||
pub const fn class_base_names() -> &'static[&'static str] {
|
||||
&[ $(stringify!($class),)* ]
|
||||
}
|
||||
};
|
||||
|
|
@ -210,8 +210,8 @@ macro_rules! classes {
|
|||
}
|
||||
}
|
||||
|
||||
impl crate::traits::IntoResource for $class {
|
||||
fn into_resource(
|
||||
impl crate::traits::ToResource for $class {
|
||||
fn to_resource(
|
||||
&self,
|
||||
_version: crate::bigfile::versions::Version,
|
||||
_platform: crate::bigfile::platforms::Platform,
|
||||
|
|
@ -267,7 +267,6 @@ macro_rules! classes {
|
|||
}
|
||||
|
||||
impl crate::traits::FromResource for $class {
|
||||
#[allow(unused_imports)]
|
||||
fn from_resource(
|
||||
resource: &crate::bigfile::resource::Resource,
|
||||
version: crate::bigfile::versions::Version,
|
||||
|
|
@ -288,9 +287,9 @@ macro_rules! classes {
|
|||
}
|
||||
}
|
||||
|
||||
impl crate::traits::IntoResource for $class {
|
||||
#[allow(unused_imports)]
|
||||
fn into_resource(
|
||||
impl crate::traits::ToResource for $class {
|
||||
#[expect(unused_imports)]
|
||||
fn to_resource(
|
||||
&self,
|
||||
version: crate::bigfile::versions::Version,
|
||||
platform: crate::bigfile::platforms::Platform,
|
||||
|
|
@ -300,7 +299,7 @@ macro_rules! classes {
|
|||
use crate::bigfile::versions::Version::*;
|
||||
match self {
|
||||
$($class::$variant(class) => {
|
||||
<$variant as crate::traits::IntoResource>::into_resource(class, version, platform, name_context)
|
||||
<$variant as crate::traits::ToResource>::to_resource(class, version, platform, name_context)
|
||||
})*
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ impl NameContext {
|
|||
scope::scope_mut(self, f)
|
||||
}
|
||||
|
||||
pub fn name_type(&self) -> NameType {
|
||||
pub const fn name_type(&self) -> NameType {
|
||||
self.name_type
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ impl Name {
|
|||
self.0
|
||||
}
|
||||
|
||||
pub fn with_context<'a>(&self, name_context: &'a NameContext) -> NameWithContext<'a> {
|
||||
pub const fn with_context<'a>(&self, name_context: &'a NameContext) -> NameWithContext<'a> {
|
||||
NameWithContext {
|
||||
name: *self,
|
||||
name_context,
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ pub trait FromResource: Sized {
|
|||
) -> BffResult<Self>;
|
||||
}
|
||||
|
||||
pub trait IntoResource {
|
||||
fn into_resource(
|
||||
pub trait ToResource {
|
||||
fn to_resource(
|
||||
&self,
|
||||
version: Version,
|
||||
platform: Platform,
|
||||
|
|
|
|||
|
|
@ -381,7 +381,7 @@ const CPS_VERSION: &[u8; 8] = b"OPAL_1.0";
|
|||
const CPS_FIRST_CHAR: u8 = b'O';
|
||||
const CPS_SEED_STEP: u8 = 37;
|
||||
|
||||
#[allow(clippy::unbuffered_bytes)]
|
||||
#[expect(clippy::unbuffered_bytes)]
|
||||
pub fn cps_copy<R: Read, W: Write>(reader: R, writer: &mut W) -> BffResult<()> {
|
||||
let mut seed = CPS_FIRST_CHAR;
|
||||
for byte in reader.bytes() {
|
||||
|
|
@ -401,7 +401,6 @@ pub fn cps_buffer(data: &mut [u8]) {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::unbuffered_bytes)]
|
||||
#[binrw::parser(reader)]
|
||||
fn cps_crypt() -> BinResult<Vec<u8>> {
|
||||
let mut data = Vec::new();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::io::{Read, Write};
|
|||
|
||||
use crate::BffResult;
|
||||
|
||||
#[allow(clippy::unbuffered_bytes)]
|
||||
#[expect(clippy::unbuffered_bytes)]
|
||||
pub fn csc_copy<R: Read, W: Write>(reader: R, writer: &mut W, key: u8) -> BffResult<()> {
|
||||
for byte in reader.bytes() {
|
||||
let byte = byte?;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use bff::bigfile::platforms::Platform;
|
|||
use bff::bigfile::resource::{BffClass, BffResourceHeader, Resource};
|
||||
use bff::class::Class;
|
||||
use bff::names::NameContext;
|
||||
use bff::traits::{Export, FromResource, Import, IntoResource};
|
||||
use bff::traits::{Export, FromResource, Import, ToResource};
|
||||
use binrw::io::BufReader;
|
||||
|
||||
use crate::path_helpers::resolve_bigfile_path;
|
||||
|
|
@ -77,7 +77,7 @@ fn roundtrip_resources(bigfile_path_str: String) {
|
|||
|
||||
let new_resource: Resource = roundtripped_bff_class
|
||||
.class
|
||||
.into_resource(version.clone(), platform, &name_context)
|
||||
.to_resource(version.clone(), platform, &name_context)
|
||||
.unwrap();
|
||||
let resource_name = resource.name.with_context(&name_context).to_string();
|
||||
let class_name = resource.class_name.with_context(&name_context).to_string();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue