Skip to content

Commit

Permalink
clippy hell
Browse files Browse the repository at this point in the history
Only ran clippy on orthrus_core, the rest are knock on effects, waiting until rewriting to address other crates
  • Loading branch information
NWPlayer123 committed Oct 4, 2024
1 parent 3083895 commit 4a1cf8c
Show file tree
Hide file tree
Showing 66 changed files with 279 additions and 283 deletions.
359 changes: 195 additions & 164 deletions crates/core/src/data.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "alloc")]
#[allow(unused_imports)] //TODO: verify no_std again
#[expect(unused_imports, reason = "TODO: verify no_std still works")]
mod no_std {
extern crate alloc;
pub use alloc::boxed::Box;
pub use alloc::format;
pub use alloc::string::String;
use alloc::boxed::Box;
use alloc::format;
use alloc::string::String;
}

pub mod prelude;
Expand Down
12 changes: 1 addition & 11 deletions crates/core/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
//! Convenient re-exports of commonly used data types, designed to make crate usage painless.
//!
//! For example, you can work with [`DataCursor`] directly, but you have to explicitly refer to
//! [`data::Error`].
//!
//! The contents of this module can be used by including the following in any module:
//! ```
//! use orthrus_core::prelude::*;
//! ```

#[doc(inline)]
pub use crate::data::{
ByteStream, DataCursor, DataCursorMut, DataCursorRef, Endian, EndianExt, ReadExt, SeekExt, WriteExt,
ByteStream, DataCursor, DataCursorMut, DataCursorRef, Endian, EndianExt, ReadExt, SeekExt, WriteExt, DataError
};
#[doc(inline)]
pub use crate::identify::{FileIdentifier, FileInfo, IdentifyFn};

/// Includes [`data::Error`], which is used in Results returned by [`DataCursor`],
/// [`DataCursorRef`], and [`DataCursorMut`].
pub mod data {
#[doc(inline)]
pub use crate::data::Error;
}

/// Includes [`util::format_size`], which allows for pretty-print of various lengths.
pub mod util {
#[doc(inline)]
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::no_std::*;
/// This function uses f64, which on a 64-bit system will lose precision if the length is too large,
/// but it should still round to a close-enough value.
#[must_use]
#[inline]
pub fn format_size(length: usize) -> String {
const UNITS: [&str; 7] = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB"];
let mut size = length as f64;
Expand Down
10 changes: 5 additions & 5 deletions crates/jsystem/src/rarc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ impl From<std::io::Error> for Error {
}
}

impl From<data::Error> for Error {
impl From<DataError> for Error {
#[inline]
fn from(error: data::Error) -> Self {
fn from(error: DataError) -> Self {
match error {
data::Error::EndOfFile => Self::EndOfFile,
DataError::EndOfFile => Self::EndOfFile,
_ => panic!("Unexpected data::error! Something has gone horribly wrong"),
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ impl ResourceArchive {
#[inline]
fn read_header<T: ReadExt + SeekExt>(data: &mut T) -> Result<Header> {
//Store the starting position since all offsets are relative
let start_pos = data.position()?;
let start_pos = data.position();

//Read the magic and make sure we're actually parsing a Resource Archive
let magic = data.read_slice(4)?;
Expand Down Expand Up @@ -168,7 +168,7 @@ impl ResourceArchive {
#[inline]
fn read_data_header<T: ReadExt + SeekExt>(data: &mut T) -> Result<DataHeader> {
//Store the starting position since all offsets are relative
let start_pos = data.position()?;
let start_pos = data.position();

//Read data
let node_count = data.read_u32()?;
Expand Down
6 changes: 3 additions & 3 deletions crates/nintendoware/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ impl From<std::io::Error> for Error {
}
}

impl From<data::Error> for Error {
impl From<DataError> for Error {
#[inline]
fn from(error: data::Error) -> Self {
fn from(error: DataError) -> Self {
match error {
data::Error::EndOfFile => Self::EndOfFile,
DataError::EndOfFile => Self::EndOfFile,
_ => panic!("Unexpected data::error! Something has gone horribly wrong"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nintendoware/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! use orthrus_nintendoware::prelude::*;
//! ```

#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub mod Switch {
#[doc(inline)]
pub use crate::switch::BFSAR;
Expand Down
26 changes: 13 additions & 13 deletions crates/nintendoware/src/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Identifier {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ByteOrderMark(u16);

#[allow(non_upper_case_globals)]
#[expect(non_upper_case_globals)]
impl ByteOrderMark {
pub const Big: ByteOrderMark = ByteOrderMark(0xFEFF);
pub const Little: ByteOrderMark = ByteOrderMark(0xFFFE);
Expand Down Expand Up @@ -332,7 +332,7 @@ impl Read for StreamSoundExtension {
stream_type_info: data.read_u32()?,
loop_start_frame: data.read_u32()?,
loop_end_frame: data.read_u32()?,
temp_position: data.position()? - 8,
temp_position: data.position() - 8,
})
}
}
Expand All @@ -354,7 +354,7 @@ struct StreamTrackInfo {
impl Read for StreamTrackInfo {
fn read<T: ReadExt + SeekExt>(data: &mut T) -> Result<Self> {
// Save our relative position
let offset = data.position()?;
let offset = data.position();

let mut info = Self::default();
info.volume = data.read_u8()?;
Expand All @@ -379,7 +379,7 @@ impl Read for StreamTrackInfo {
}

// Now we need to align, and theoretically that's where send_value is
let position = data.position()?;
let position = data.position();
data.set_position((position + 3) & !3)?;

data.set_position(offset + send_value_ref.offset as usize)?;
Expand All @@ -403,7 +403,7 @@ struct StreamSoundInfo {
impl Read for StreamSoundInfo {
fn read<T: ReadExt + SeekExt>(data: &mut T) -> Result<Self> {
// Save relative position
let offset = data.position()?;
let offset = data.position();

let mut info = Self::default();

Expand Down Expand Up @@ -748,7 +748,7 @@ impl SoundInfo {

impl Read for SoundInfo {
fn read<T: ReadExt + SeekExt>(data: &mut T) -> Result<Self> {
let readback = data.position()?;
let readback = data.position();

let file_id = data.read_u32()?;
let player_id = data.read_u32()?;
Expand All @@ -762,7 +762,7 @@ impl Read for SoundInfo {

let mut info = Self { file_id, player_id, volume, filter, options, ..Default::default() };

let position = data.position()?;
let position = data.position();

info.read_string_id(data, position);
info.read_pan_mode(data, position);
Expand Down Expand Up @@ -806,7 +806,7 @@ impl StringBlock {

fn read_string_table<T: ReadExt + SeekExt>(data: &mut T) -> Result<Vec<String>> {
// Store relative position
let offset = data.position()?;
let offset = data.position();

// Read in the reference table
let references: Vec<SizedReference> = Table::read(data)?;
Expand All @@ -821,7 +821,8 @@ impl StringBlock {

// Read the string and store it, includes the trailing \0
let string = data.read_slice(reference.size as usize)?.to_vec();
strings.push(String::from_utf8(string).map_err(|_| data::Error::InvalidUtf8)?);
strings
.push(String::from_utf8(string).map_err(|source| DataError::InvalidString { source })?);
}
_ => InvalidDataSnafu { reason: "Unexpected String Identifier!" }.fail()?,
}
Expand All @@ -841,7 +842,7 @@ impl Read for StringBlock {
);

// Store the relative position for all offsets
let offset = data.position()?;
let offset = data.position();

// Read both sections
let mut sections: [Reference; 2] = Default::default();
Expand Down Expand Up @@ -885,7 +886,7 @@ impl InfoBlock {
let _header = SectionHeader::read(data)?;

// Store relative position
let offset = data.position()?;
let offset = data.position();

let mut info = Self::default();

Expand Down Expand Up @@ -960,7 +961,6 @@ impl BFSAR {
pub const MAGIC: [u8; 4] = *b"FSAR";

#[inline]
#[allow(dead_code)]
fn read_header<T: ReadExt + SeekExt>(data: &mut T) -> Result<BinaryHeader> {
// Read the header
let header = BinaryHeader::read(data)?;
Expand Down Expand Up @@ -1015,7 +1015,7 @@ impl BFSAR {
}

// Align to a 32-byte boundary
let position = data.position()?;
let position = data.position();
data.set_position((position + 31) & !31)?;

// Then read all the section data
Expand Down
10 changes: 5 additions & 5 deletions crates/panda3d/src/bam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ impl From<std::io::Error> for Error {
}
}

impl From<data::Error> for Error {
impl From<DataError> for Error {
#[inline]
fn from(error: data::Error) -> Self {
fn from(error: DataError) -> Self {
match error {
data::Error::EndOfFile => Self::EndOfFile,
DataError::EndOfFile => Self::EndOfFile,
_ => panic!("Unexpected data::error! Something has gone horribly wrong"),
}
}
Expand Down Expand Up @@ -276,10 +276,10 @@ impl BinaryAsset {
//println!("Filling in {} from {:#X}", type_name, data.position());
self.fillin(data, &type_name)?;
}
if data.position()? != data.len()? {
if data.position() != data.len()? {
println!(
"Finished at {:#X}, Data size {:#X}\n",
data.position()?,
data.position(),
data.len()?
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/panda3d/src/bam2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum Error {
ReadFile { source: std::io::Error, path: String },
}

#[allow(dead_code)]
#[expect(dead_code)]
pub struct BinaryAsset {
data: Vec<u8>,
}
Expand Down
10 changes: 5 additions & 5 deletions crates/panda3d/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'a> Datagram<'a> {
#[inline]
pub(crate) fn new<T: ReadExt>(
data: &'a mut T, endian: Endian, float_type: bool,
) -> Result<Self, data::Error> {
) -> Result<Self, DataError> {
let length = data.read_u32()? as usize;
let data = match data.read_slice(length)? {
Cow::Borrowed(data) => data,
Expand All @@ -37,22 +37,22 @@ impl<'a> Datagram<'a> {
Ok(Self { cursor: DataCursorRef::new(&data, endian), float_type })
}

pub(crate) fn read_string(&mut self) -> Result<String, data::Error> {
pub(crate) fn read_string(&mut self) -> Result<String, DataError> {
let length = self.cursor.read_u16()?;
let slice = self.cursor.read_slice(length.into())?;
let string = core::str::from_utf8(&slice).map_err(|_| data::Error::InvalidUtf8)?;
let string = core::str::from_utf8(&slice).map_err(|source| DataError::InvalidStr { source })?;
Ok(string.to_owned())
}

pub(crate) fn read_float(&mut self) -> Result<f32, data::Error> {
pub(crate) fn read_float(&mut self) -> Result<f32, DataError> {
if self.float_type == true {
Ok(self.cursor.read_f64()? as f32)
} else {
self.cursor.read_f32()
}
}

pub(crate) fn read_bool(&mut self) -> Result<bool, data::Error> {
pub(crate) fn read_bool(&mut self) -> Result<bool, DataError> {
Ok(self.cursor.read_u8()? != 0)
}
}
Expand Down
9 changes: 3 additions & 6 deletions crates/panda3d/src/multifile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,16 @@ impl From<std::io::Error> for Error {
}
}

impl From<data::Error> for Error {
impl From<DataError> for Error {
#[inline]
fn from(error: data::Error) -> Self {
fn from(error: DataError) -> Self {
match error {
data::Error::EndOfFile => Self::EndOfFile,
DataError::EndOfFile => Self::EndOfFile,
_ => panic!("Unexpected data::error! Something has gone horribly wrong"),
}
}
}

#[allow(dead_code)]
struct Header {
version: Version,
scale_factor: u32,
Expand All @@ -170,7 +169,6 @@ struct Header {
///
/// For more details on the Multifile format, see the [module documentation](self#format).
#[derive(Debug)]
#[allow(dead_code)]
pub struct Multifile {
data: DataCursor,
files: Vec<Subfile>,
Expand Down Expand Up @@ -216,7 +214,6 @@ impl Multifile {
/// Multifile, or [`UnknownVersion`](Error::UnknownVersion) if the Multifile version is
/// too new to be supported.
#[inline]
#[allow(dead_code)]
fn read_header<T: ReadExt>(data: &mut T) -> Result<Header> {
//Read the magic and make sure we're actually parsing a Multifile
let mut magic = [0u8; 6];
Expand Down
10 changes: 5 additions & 5 deletions crates/panda3d/src/multifile2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub enum Error {
UnknownVersion,
}

impl From<data::Error> for Error {
impl From<DataError> for Error {
#[inline]
fn from(error: data::Error) -> Self {
fn from(error: DataError) -> Self {
match error {
data::Error::EndOfFile => Self::EndOfFile,
DataError::EndOfFile => Self::EndOfFile,
_ => todo!(),
}
}
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct MultifileHeader {
timestamp: u32,
}

#[allow(dead_code)]
#[expect(dead_code)]
pub struct Multifile {
header: MultifileHeader,
files: BTreeMap<String, Subfile>,
Expand Down Expand Up @@ -281,7 +281,7 @@ impl SubfileHeader {
}
}

#[allow(dead_code)]
#[expect(dead_code)]
struct Subfile {
attributes: Attributes,
original_length: u32,
Expand Down
1 change: 0 additions & 1 deletion crates/panda3d/src/nodes/anim_bundle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::prelude::*;

#[derive(Debug, Default)]
#[allow(dead_code)]
pub(crate) struct AnimBundle {
pub group: AnimGroup,
pub fps: f32,
Expand Down
1 change: 0 additions & 1 deletion crates/panda3d/src/nodes/anim_bundle_node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::prelude::*;

#[derive(Debug, Default)]
#[allow(dead_code)]
pub(crate) struct AnimBundleNode {
pub node: PandaNode,
pub anim_bundle_ref: u32,
Expand Down
2 changes: 1 addition & 1 deletion crates/panda3d/src/nodes/anim_channel_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::prelude::*;

// This is technically a generic but I don't feel like making one
#[derive(Debug, Default)]
#[allow(dead_code)]
#[expect(dead_code)]
pub(crate) struct AnimChannelMatrix {
pub group: AnimGroup,
pub last_frame: u16,
Expand Down
Loading

0 comments on commit 4a1cf8c

Please sign in to comment.