From b1d673faf34d3c71bdc23b12464322991c3f4cba Mon Sep 17 00:00:00 2001 From: Marrub Date: Wed, 20 Feb 2019 21:33:57 -0500 Subject: [PATCH] rustfmt --- src/durandal/bin.rs | 37 +++++------------- src/durandal/cenum.rs | 5 +-- src/durandal/err.rs | 10 +---- src/durandal/fixed.rs | 87 +++++++++---------------------------------- src/durandal/image.rs | 10 +---- src/durandal/sound.rs | 26 ++++++------- src/main.rs | 52 +++++++++++++++++++------- src/marathon/map.rs | 3 +- src/marathon/pict.rs | 19 ++++++---- src/marathon/shp.rs | 24 ++++++------ src/marathon/snd.rs | 2 +- src/marathon/wad.rs | 4 +- tests/epnt.rs | 6 ++- tests/minf.rs | 17 ++++----- 14 files changed, 121 insertions(+), 181 deletions(-) diff --git a/src/durandal/bin.rs b/src/durandal/bin.rs index de3b484..4c580de 100644 --- a/src/durandal/bin.rs +++ b/src/durandal/bin.rs @@ -92,30 +92,11 @@ macro_rules! read_data { }; } -pub fn ident(b: &[u8]) -> Ident -{ - [b[0], b[1], b[2], b[3]] -} - -pub fn u32b(b: &[u8]) -> u32 -{ - u32::from_be_bytes([b[0], b[1], b[2], b[3]]) -} - -pub fn u16b(b: &[u8]) -> u16 -{ - u16::from_be_bytes([b[0], b[1]]) -} - -pub fn i32b(b: &[u8]) -> i32 -{ - i32::from_be_bytes([b[0], b[1], b[2], b[3]]) -} - -pub fn i16b(b: &[u8]) -> i16 -{ - i16::from_be_bytes([b[0], b[1]]) -} +pub fn ident(b: &[u8]) -> Ident {[b[0], b[1], b[2], b[3]]} +pub fn u32b(b: &[u8]) -> u32 {u32::from_be_bytes([b[0], b[1], b[2], b[3]])} +pub fn u16b(b: &[u8]) -> u16 {u16::from_be_bytes([b[0], b[1]])} +pub fn i32b(b: &[u8]) -> i32 {i32::from_be_bytes([b[0], b[1], b[2], b[3]])} +pub fn i16b(b: &[u8]) -> i16 {i16::from_be_bytes([b[0], b[1]])} pub fn rd_array(b: &[u8], read: F) -> ResultS> where T: Sized, @@ -134,10 +115,10 @@ pub fn rd_array(b: &[u8], read: F) -> ResultS> } pub fn rd_ofstable(b: &[u8], - mut p: usize, - num: usize, - read: F) - -> ResultS> + mut p: usize, + num: usize, + read: F) + -> ResultS> where T: Sized, F: Fn(&[u8]) -> ResultS { diff --git a/src/durandal/cenum.rs b/src/durandal/cenum.rs index bc0200d..b7b4d22 100644 --- a/src/durandal/cenum.rs +++ b/src/durandal/cenum.rs @@ -59,10 +59,7 @@ mod test #[test] #[should_panic] - fn c_enum_should_error() - { - TestEnum::from_repr(3).unwrap(); - } + fn c_enum_should_error() {TestEnum::from_repr(3).unwrap();} } // EOF diff --git a/src/durandal/err.rs b/src/durandal/err.rs index b5cbe85..af68a92 100644 --- a/src/durandal/err.rs +++ b/src/durandal/err.rs @@ -19,10 +19,7 @@ macro_rules! bail { }; } -pub fn err_msg(msg: &'static str) -> Error -{ - Error::from(ErrMsg(msg)) -} +pub fn err_msg(msg: &'static str) -> Error {Error::from(ErrMsg(msg))} impl Fail for ReprError {} impl Fail for ErrMsg {} @@ -45,10 +42,7 @@ impl fmt::Debug for ReprError impl fmt::Display for ErrMsg { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result - { - f.write_str(self.0) - } + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {f.write_str(self.0)} } impl fmt::Debug for ErrMsg diff --git a/src/durandal/fixed.rs b/src/durandal/fixed.rs index ea69373..ac32730 100644 --- a/src/durandal/fixed.rs +++ b/src/durandal/fixed.rs @@ -5,9 +5,7 @@ use std::{fmt::{self, Write}, ops}; macro_rules! define_fixed_type { - ( - $Type:ident : $IT:ident, $UT:ident, $LT:ident, $FracBits:expr - ) => { + ($Type:ident : $IT:ident, $UT:ident, $LT:ident, $FracBits:expr) => { #[derive(Clone, PartialEq, Serialize)] pub struct $Type($IT); @@ -15,42 +13,15 @@ macro_rules! define_fixed_type { { const FRACBITS: $UT = $FracBits; const FRACMASK: $UT = (1 << Self::FRACBITS) - 1; - const ONE: $IT = 1 << Self::FRACBITS; + const ONE: $IT = 1 << Self::FRACBITS; - pub fn to_bits(&self) -> $UT - { - self.0 as $UT - } - - pub fn set_bits(&mut self, bits: $UT) - { - self.0 = bits as $IT - } - - pub const fn from_bits(bits: $UT) -> Self - { - $Type(bits as $IT) - } - - pub fn integ(&self) -> $LT - { - (self.0 >> Self::FRACBITS) as $LT - } - - pub fn fract(&self) -> u16 - { - (self.0 as $UT & Self::FRACMASK) as u16 - } - - pub fn mul_i(&self, n: $LT) -> Self - { - $Type(self.0 * $IT::from(n)) - } - - pub fn div_i(&self, n: $LT) -> Self - { - $Type(self.0 / $IT::from(n)) - } + pub fn to_bits(&self) -> $UT {self.0 as $UT} + pub fn set_bits(&mut self, bits: $UT) {self.0 = bits as $IT} + pub const fn from_bits(bits: $UT) -> Self {$Type(bits as $IT)} + pub fn integ(&self) -> $LT {(self.0 >> Self::FRACBITS) as $LT} + pub fn fract(&self) -> u16 {(self.0 as $UT & Self::FRACMASK) as u16} + pub fn mul_i(&self, n: $LT) -> Self {$Type(self.0 * $IT::from(n))} + pub fn div_i(&self, n: $LT) -> Self {$Type(self.0 / $IT::from(n))} #[inline] fn fx_div(x: $IT, y: $IT) -> $IT @@ -67,70 +38,49 @@ macro_rules! define_fixed_type { impl From<$LT> for $Type { - fn from(n: $LT) -> Self - { - $Type($IT::from(n) << Self::FRACBITS) - } + fn from(n: $LT) -> Self {$Type($IT::from(n) << Self::FRACBITS)} } impl ops::Add for $Type { type Output = Self; - fn add(self, o: Self) -> Self - { - $Type(self.0 + o.0) - } + fn add(self, o: Self) -> Self {$Type(self.0 + o.0)} } impl ops::Sub for $Type { type Output = Self; - fn sub(self, o: Self) -> Self - { - $Type(self.0 - o.0) - } + fn sub(self, o: Self) -> Self {$Type(self.0 - o.0)} } impl ops::Mul for $Type { type Output = Self; - fn mul(self, o: Self) -> Self - { - $Type(Self::fx_mul(self.0, o.0)) - } + fn mul(self, o: Self) -> Self {$Type(Self::fx_mul(self.0, o.0))} } impl ops::Div for $Type { type Output = Self; - fn div(self, o: Self) -> Self - { - $Type(Self::fx_div(self.0, o.0)) - } + fn div(self, o: Self) -> Self {$Type(Self::fx_div(self.0, o.0))} } impl ops::Neg for $Type { type Output = Self; - fn neg(self) -> Self - { - $Type(-self.0) - } + fn neg(self) -> Self {$Type(-self.0)} } impl ops::Not for $Type { type Output = Self; - fn not(self) -> Self - { - $Type(!self.0) - } + fn not(self) -> Self {$Type(!self.0)} } impl fmt::Display for $Type @@ -183,10 +133,7 @@ fn fixed_basic_ops() #[test] #[should_panic] #[allow(unused_must_use)] -fn fixed_overflow() -{ - Fixed::from(i16::max_value()) + 1.into(); -} +fn fixed_overflow() {Fixed::from(i16::max_value()) + 1.into();} #[test] fn fixed_printing() diff --git a/src/durandal/image.rs b/src/durandal/image.rs index 83a8d60..b2275e4 100644 --- a/src/durandal/image.rs +++ b/src/durandal/image.rs @@ -142,10 +142,7 @@ impl Image for Image8 impl Color16 { - pub const fn new(r: u16, g: u16, b: u16) -> Color16 - { - Color16(r, g, b) - } + pub const fn new(r: u16, g: u16, b: u16) -> Color16 {Color16(r, g, b)} } impl Color for Color16 @@ -158,10 +155,7 @@ impl Color for Color16 impl Color8 { - pub const fn new(r: u8, g: u8, b: u8) -> Color8 - { - Color8(r, g, b) - } + pub const fn new(r: u8, g: u8, b: u8) -> Color8 {Color8(r, g, b)} } impl Color for Color8 diff --git a/src/durandal/sound.rs b/src/durandal/sound.rs index d71dab1..476cf2a 100644 --- a/src/durandal/sound.rs +++ b/src/durandal/sound.rs @@ -15,11 +15,11 @@ pub fn write_wav(out: &mut impl io::Write, snd: &impl Sound) -> ResultS<()> out.write_all(b"WAVE")?; out.write_all(b"fmt ")?; out.write_all(&16u32.to_le_bytes())?; - out.write_all(&1u16.to_le_bytes())?; // PCM - out.write_all(&1u16.to_le_bytes())?; // mono - out.write_all(&rate.to_le_bytes())?; // rate - out.write_all(&bps.to_le_bytes())?; // bytes per second - out.write_all(&2u16.to_le_bytes())?; // block alignment + out.write_all(&1u16.to_le_bytes())?; // PCM + out.write_all(&1u16.to_le_bytes())?; // mono + out.write_all(&rate.to_le_bytes())?; // rate + out.write_all(&bps.to_le_bytes())?; // bytes per second + out.write_all(&2u16.to_le_bytes())?; // block alignment out.write_all(&16u16.to_le_bytes())?; // bits per sample out.write_all(b"data")?; out.write_all(&ssize.to_le_bytes())?; @@ -44,10 +44,7 @@ pub trait Sound fn lp_beg(&self) -> usize; fn lp_end(&self) -> usize; - fn is_empty(&self) -> bool - { - self.len() == 0 - } + fn is_empty(&self) -> bool {self.len() == 0} fn get(&self, p: usize) -> Option { @@ -68,7 +65,8 @@ impl Sound16 } /// Creates a new Sound16 from an unsigned 8-bit stream. - pub fn new_from_8(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) -> Self + pub fn new_from_8(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) + -> Self { let mut snd = Sound16::new(rate, lp_beg, lp_end, b.len()); @@ -80,7 +78,8 @@ impl Sound16 } /// Creates a new Sound16 from a signed 16-bit stream. - pub fn new_from_16(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) -> Self + pub fn new_from_16(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) + -> Self { let mut snd = Sound16::new(rate, lp_beg, lp_end, b.len() / 2); @@ -92,10 +91,7 @@ impl Sound16 } /// Creates a signed 16-bit sample from an unsigned 8-bit sample. - pub fn sample_from_8(sample: u8) -> i16 - { - (i16::from(sample) - 0x80) << 8 - } + pub fn sample_from_8(sample: u8) -> i16 {(i16::from(sample) - 0x80) << 8} } impl Sound for Sound16 diff --git a/src/main.rs b/src/main.rs index e708797..264508b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -201,43 +201,69 @@ fn main() -> ResultS<()> ap.refer(&mut opt.inputs) .add_argument("inputs", Collect, "Input files"); - arg!("--shp-write-tab", opt.shp_tab, StoreTrue, + arg!("--shp-write-tab", + opt.shp_tab, + StoreTrue, "shp: Dump all CLUTs as YAML to standard output"); - arg!("--shp-dump-bitmaps", opt.shp_bmp, StoreTrue, + arg!("--shp-dump-bitmaps", + opt.shp_bmp, + StoreTrue, "shp: Dump bitmaps into a folder"); - arg!("--shp-dump-more-bitmaps", opt.shp_bmp_all, StoreTrue, + arg!("--shp-dump-more-bitmaps", + opt.shp_bmp_all, + StoreTrue, "shp: Dump all color variations of each bitmap"); - arg!("--shp-write-frm", opt.shp_frm, StoreTrue, + arg!("--shp-write-frm", + opt.shp_frm, + StoreTrue, "shp: Dump all frames as YAML to standard output"); - arg!("--shp-write-seq", opt.shp_seq, StoreTrue, + arg!("--shp-write-seq", + opt.shp_seq, + StoreTrue, "shp: Dump all sequences as YAML to standard output"); - arg!("--snd-write", opt.snd_write, StoreTrue, + arg!("--snd-write", + opt.snd_write, + StoreTrue, "snd: Dump all sound headers as YAML to standard output"); - arg!("--snd-dump", opt.snd_dump, StoreTrue, + arg!("--snd-dump", + opt.snd_dump, + StoreTrue, "snd: Dump all sounds to WAVE files"); - arg!("--wad-dump-all", opt.wad_all, StoreTrue, + arg!("--wad-dump-all", + opt.wad_all, + StoreTrue, "wad: Dump all chunks into a folder"); - arg!("--wad-dump-unknown", opt.wad_unknown, StoreTrue, + arg!("--wad-dump-unknown", + opt.wad_unknown, + StoreTrue, "wad: Dump all unknown chunks into a folder"); - arg!("--wad-write-header", opt.wad_header, StoreTrue, + arg!("--wad-write-header", + opt.wad_header, + StoreTrue, "wad: Dump header info as YAML to standard output"); - arg!("--wad-write-chunks", opt.wad_c_temp, Store, + arg!("--wad-write-chunks", + opt.wad_c_temp, + Store, "wad: Dump specified chunks in various formats"); - arg!("--out-dir", opt.out_dir, Store, + arg!("--out-dir", + opt.out_dir, + Store, "Sets output directory for dump options"); - arg!("--out-debug", opt.out_debug, StoreTrue, + arg!("--out-debug", + opt.out_debug, + StoreTrue, "Writes debugging output rather than YAML"); ap.parse_args_or_exit(); diff --git a/src/marathon/map.rs b/src/marathon/map.rs index 569e193..2c26249 100644 --- a/src/marathon/map.rs +++ b/src/marathon/map.rs @@ -1,5 +1,4 @@ -use crate::{durandal::{bin::*, err::*, fixed::*, - text::mac_roman_conv}, +use crate::{durandal::{bin::*, err::*, fixed::*, text::mac_roman_conv}, marathon::xfer::TransferMode}; use bitflags::bitflags; use serde::Serialize; diff --git a/src/marathon/pict.rs b/src/marathon/pict.rs index 3ffc345..65aad00 100644 --- a/src/marathon/pict.rs +++ b/src/marathon/pict.rs @@ -78,12 +78,17 @@ fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS // RLE compressed 1, 2, 4 or 8 bit colormap indices for _ in 0..im.h() { let (d, pp) = read_rle(&b[p..], hdr.pitch, false)?; - let d = if hdr.depth < 8 {expand_data(d, hdr.depth)?} else {d}; + let d = if hdr.depth < 8 { + expand_data(d, hdr.depth)? + } else { + d + }; p += pp; for &idx in &d { - im.cr.push(ok!(clut.get(idx as usize), "invalid index")?.clone()); + im.cr + .push(ok!(clut.get(idx as usize), "invalid index")?.clone()); } } @@ -133,7 +138,10 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS { let mut p = 0; - if hdr.pitch < 8 || hdr.pack_t == PackType::None || hdr.pack_t == PackType::NoPad { + if hdr.pitch < 8 || + hdr.pack_t == PackType::None || + hdr.pack_t == PackType::NoPad + { // uncompressed RGB8 or XRGB8 for _ in 0..im.h() { for _ in 0..im.w() { @@ -178,10 +186,7 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS } /// Process a CopyBits operation. -fn read_pm_area(im: Image8, - b: &[u8], - pack: bool, - clip: bool) +fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool) -> ResultS { let p = if pack {0} else {4}; diff --git a/src/marathon/shp.rs b/src/marathon/shp.rs index 4c7827c..1bac668 100644 --- a/src/marathon/shp.rs +++ b/src/marathon/shp.rs @@ -61,10 +61,10 @@ fn bitmap(b: &[u8]) -> ResultS depth = u16[8]; } - let compr = compr == u16::max_value(); - let flags = ok!(BmpFlags::from_bits(flags), "bad BmpFlags")?; - let alpha = flags.contains(BmpFlags::Transparent); - let cmajr = flags.contains(BmpFlags::ColumnMajor); + let compr = compr == u16::max_value(); + let flags = ok!(BmpFlags::from_bits(flags), "bad BmpFlags")?; + let alpha = flags.contains(BmpFlags::Transparent); + let cmajr = flags.contains(BmpFlags::ColumnMajor); if depth != 8 { bail!("invalid bit depth (should always be 8)"); @@ -131,14 +131,14 @@ fn frame(b: &[u8]) -> ResultS wrl_y = u16[26]; } - let flags = ok!(FrameFlags::from_bits(flags), "bad flag")?; - let min_lt = Fixed::from_bits(min_lt); - let wrl_l = Unit::from_bits(wrl_l); - let wrl_r = Unit::from_bits(wrl_r); - let wrl_t = Unit::from_bits(wrl_t); - let wrl_b = Unit::from_bits(wrl_b); - let wrl_x = Unit::from_bits(wrl_x); - let wrl_y = Unit::from_bits(wrl_y); + let flags = ok!(FrameFlags::from_bits(flags), "bad flag")?; + let min_lt = Fixed::from_bits(min_lt); + let wrl_l = Unit::from_bits(wrl_l); + let wrl_r = Unit::from_bits(wrl_r); + let wrl_t = Unit::from_bits(wrl_t); + let wrl_b = Unit::from_bits(wrl_b); + let wrl_x = Unit::from_bits(wrl_x); + let wrl_y = Unit::from_bits(wrl_y); Ok(Frame{flags, min_lt, bmp_ind, wrl_l, wrl_r, wrl_t, wrl_b, wrl_x, wrl_y}) } diff --git a/src/marathon/snd.rs b/src/marathon/snd.rs index 22f66a8..9d36cb7 100644 --- a/src/marathon/snd.rs +++ b/src/marathon/snd.rs @@ -33,7 +33,7 @@ fn sound(b: &[u8]) -> ResultS let stream = &b[63..63 + len * 2]; Ok(Sound16::new_from_16(rate, lp_beg, lp_end, stream)) } - 8 => { + 8 => { let stream = &b[63..63 + len]; Ok(Sound16::new_from_8(rate, lp_beg, lp_end, stream)) } diff --git a/src/marathon/wad.rs b/src/marathon/wad.rs index 8a7ba55..941f949 100644 --- a/src/marathon/wad.rs +++ b/src/marathon/wad.rs @@ -77,8 +77,8 @@ fn get_chunks(b: &[u8], cnksize: usize) -> ResultS size = u32[p + 8] as usize; } - let beg = p + cnksize; - let end = beg + size; + let beg = p + cnksize; + let end = beg + size; chunks.insert(iden, &b[beg..end]); diff --git a/tests/epnt.rs b/tests/epnt.rs index ed59207..60bb59b 100644 --- a/tests/epnt.rs +++ b/tests/epnt.rs @@ -1,9 +1,11 @@ -use maraiah::{durandal::{bin, fixed::*}, marathon::map}; +use maraiah::{durandal::{bin, fixed::*}, + marathon::map}; #[test] fn read_epnt_must_process_this() { - assert_eq!(bin::rd_array(INPUT, map::read_epnt).unwrap(), OUTPUT.to_vec()); + assert_eq!(bin::rd_array(INPUT, map::read_epnt).unwrap(), + OUTPUT.to_vec()); } const INPUT: &'static [u8] = include_bytes!("data/epnt.in"); diff --git a/tests/minf.rs b/tests/minf.rs index 79b36ad..edf4dcc 100644 --- a/tests/minf.rs +++ b/tests/minf.rs @@ -3,15 +3,14 @@ use maraiah::marathon::map; #[test] fn read_minf_must_process_map0() { - assert_eq!(map::read_minf(INPUT).unwrap(), map::Minf{ - env_code: 0, - physi_id: 1, - music_id: 1, - msn_flag: map::MsnFlags::Repair, - env_flag: map::EnvFlags::empty(), - ent_flag: map::EntFlags::Solo | map::EntFlags::CoOp, - levelnam: "Waterloo Waterpark".to_string() - }); + assert_eq!(map::read_minf(INPUT).unwrap(), + map::Minf{env_code: 0, + physi_id: 1, + music_id: 1, + msn_flag: map::MsnFlags::Repair, + env_flag: map::EnvFlags::empty(), + ent_flag: map::EntFlags::Solo | map::EntFlags::CoOp, + levelnam: "Waterloo Waterpark".to_string()}); } const INPUT: &'static [u8] = include_bytes!("data/minf.in");