prettify code

This commit is contained in:
Wuelle
2021-12-30 21:59:29 +01:00
parent 5e563cddf8
commit 9a010ca0c4
17 changed files with 1312 additions and 1060 deletions

View File

@@ -2,7 +2,7 @@ use std::fmt::Debug;
use std::io;
/// A Four-character Code
///
///
/// For idetifying chunks, structured contiguous slices or segments
/// within a WAV file.
#[derive(Eq, PartialEq, Hash, Copy, Clone)]
@@ -15,8 +15,13 @@ impl FourCC {
}
impl From<[char; 4]> for FourCC {
fn from(chars : [char; 4]) -> Self {
Self([chars[0] as u8 , chars[1] as u8, chars[2] as u8, chars[3] as u8])
fn from(chars: [char; 4]) -> Self {
Self([
chars[0] as u8,
chars[1] as u8,
chars[2] as u8,
chars[3] as u8,
])
}
}
@@ -32,37 +37,45 @@ impl From<FourCC> for [u8; 4] {
}
}
impl From<&FourCC> for [char;4] {
fn from( f: &FourCC) -> Self {
[f.0[0] as char, f.0[1] as char, f.0[2] as char, f.0[3] as char,]
impl From<&FourCC> for [char; 4] {
fn from(f: &FourCC) -> Self {
[
f.0[0] as char,
f.0[1] as char,
f.0[2] as char,
f.0[3] as char,
]
}
}
impl From<FourCC> for [char;4] {
fn from( f: FourCC) -> Self {
[f.0[0] as char, f.0[1] as char, f.0[2] as char, f.0[3] as char,]
impl From<FourCC> for [char; 4] {
fn from(f: FourCC) -> Self {
[
f.0[0] as char,
f.0[1] as char,
f.0[2] as char,
f.0[3] as char,
]
}
}
impl From<&FourCC> for String {
fn from(f: &FourCC) -> Self {
let chars: [char;4] = f.into();
chars.iter().collect::<String>()
fn from(f: &FourCC) -> Self {
let chars: [char; 4] = f.into();
chars.iter().collect::<String>()
}
}
impl From<FourCC> for String {
fn from(f: FourCC) -> Self {
let chars: [char;4] = f.into();
chars.iter().collect::<String>()
fn from(f: FourCC) -> Self {
let chars: [char; 4] = f.into();
chars.iter().collect::<String>()
}
}
impl Debug for FourCC {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
let s : String = self.into();
let s: String = self.into();
write!(f, "FourCC({})", s)
}
}
@@ -72,30 +85,35 @@ pub trait ReadFourCC: io::Read {
}
pub trait WriteFourCC: io::Write {
fn write_fourcc(&mut self, fourcc :FourCC) -> Result<(), io::Error>;
fn write_fourcc(&mut self, fourcc: FourCC) -> Result<(), io::Error>;
}
impl<T> ReadFourCC for T where T: io::Read {
impl<T> ReadFourCC for T
where
T: io::Read,
{
fn read_fourcc(&mut self) -> Result<FourCC, io::Error> {
let mut buf : [u8; 4] = [0 ; 4];
let mut buf: [u8; 4] = [0; 4];
self.read_exact(&mut buf)?;
Ok( FourCC::from(buf) )
Ok(FourCC::from(buf))
}
}
impl<T> WriteFourCC for T where T: io::Write {
fn write_fourcc(&mut self, fourcc :FourCC) -> Result<(), io::Error> {
let buf : [u8; 4] = fourcc.into();
impl<T> WriteFourCC for T
where
T: io::Write,
{
fn write_fourcc(&mut self, fourcc: FourCC) -> Result<(), io::Error> {
let buf: [u8; 4] = fourcc.into();
self.write_all(&buf)?;
Ok(())
}
}
pub const RIFF_SIG: FourCC = FourCC::make(b"RIFF");
pub const WAVE_SIG: FourCC = FourCC::make(b"WAVE");
pub const RF64_SIG: FourCC = FourCC::make(b"RF64");
pub const DS64_SIG: FourCC = FourCC::make(b"ds64");
pub const RF64_SIG: FourCC = FourCC::make(b"RF64");
pub const DS64_SIG: FourCC = FourCC::make(b"ds64");
pub const BW64_SIG: FourCC = FourCC::make(b"BW64");
pub const DATA_SIG: FourCC = FourCC::make(b"data");
@@ -117,7 +135,6 @@ pub const LABL_SIG: FourCC = FourCC::make(b"labl");
pub const NOTE_SIG: FourCC = FourCC::make(b"note");
pub const LTXT_SIG: FourCC = FourCC::make(b"ltxt");
#[cfg(test)]
mod tests {
use super::*;
@@ -125,7 +142,7 @@ mod tests {
#[test]
fn test_to_string() {
let a = FourCC::make(b"a1b2");
let s : String = a.into();
let s: String = a.into();
assert_eq!(s, "a1b2");
}
}
}