Skip to content

Commit

Permalink
Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marmal95 committed May 10, 2024
1 parent b98ec9c commit a957705
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/coder/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use super::header::{AlgHeader, Header};
pub fn decode(image: RgbaImage) -> Result<(String, Vec<u8>), Box<dyn Error>> {
let mut buffer = image.into_raw();
let header = header_decoder::decode(&buffer)?;
let mut buffer = buffer.split_off(header.size() * 4);
let buffer = buffer.split_off(header.size() * 4);

let decoder = create_decoder(&header, &mut buffer);
let decoder = create_decoder(&header, &buffer);
let decoded = decoder.decode()?;
Ok(decoded)
}

fn create_decoder<'a>(header: &Header, buffer: &'a Vec<u8>) -> Box<dyn Decode + 'a> {
fn create_decoder<'a>(header: &Header, buffer: &'a [u8]) -> Box<dyn Decode + 'a> {
match &header.alg_header {
AlgHeader::Alpha(_) => Box::new(AlphaDecoder::new(buffer)),
AlgHeader::Rgb(rgb_header) => {
Expand Down
2 changes: 1 addition & 1 deletion src/coder/decoder/alpha_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct AlphaDecoder<'a> {
}

impl<'a> AlphaDecoder<'a> {
pub fn new(buffer: &'a Vec<u8>) -> Self {
pub fn new(buffer: &'a [u8]) -> Self {
Self {
iter: buffer.iter().skip(3).step_by(4),
}
Expand Down
2 changes: 1 addition & 1 deletion src/coder/decoder/header_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::coder::{
header::{AlgHeader, AlphaHeader, Header, RgbHeader, ALPHA_MODE, RGB_MODE},
};

pub fn decode(buffer: &Vec<u8>) -> Result<Header, HeaderDecodeError> {
pub fn decode(buffer: &[u8]) -> Result<Header, HeaderDecodeError> {
let mut iter = buffer.iter().skip(3).step_by(4);
let mode = *iter.next().ok_or(HeaderDecodeError(
"Not enough data to decode mode.".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/coder/decoder/rgb_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct RgbDecoder<'a> {
}

impl<'a> RgbDecoder<'a> {
pub fn new(buffer: &'a Vec<u8>, bits_per_channel: u8) -> Self {
pub fn new(buffer: &'a [u8], bits_per_channel: u8) -> Self {
RgbDecoder {
buffer: buffer.iter(),
bits_per_channel,
Expand Down
2 changes: 1 addition & 1 deletion src/coder/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn create_header(algorithm: &Algorithm) -> Header {

fn create_encoder<'a>(
algorithm: &Algorithm,
buffer: &'a mut Vec<u8>,
buffer: &'a mut [u8],
data: Vec<u8>,
secret_filename: String,
) -> Box<dyn Encode + 'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/coder/encoder/alpha_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct AlphaEncoder<'a> {
}

impl<'a> AlphaEncoder<'a> {
pub fn new(buffer: &'a mut Vec<u8>, data: Vec<u8>, file_name: String) -> Self {
pub fn new(buffer: &'a mut [u8], data: Vec<u8>, file_name: String) -> Self {
AlphaEncoder {
buffer: buffer.iter_mut().skip(3).step_by(4),
data,
Expand Down
2 changes: 1 addition & 1 deletion src/coder/encoder/header_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::coder::{
header::{AlgHeader, Header, RgbHeader},
};

pub fn encode(header: Header, buffer: &mut Vec<u8>) -> Result<(), HeaderEncodeError> {
pub fn encode(header: Header, buffer: &mut [u8]) -> Result<(), HeaderEncodeError> {
let mut iter = buffer.iter_mut().skip(3).step_by(4);
let mode_byte = iter.next().ok_or(HeaderEncodeError(
"Not enough to encode header mode.".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/coder/encoder/rgb_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct RgbEncoder<'a> {

impl<'a> RgbEncoder<'a> {
pub fn new(
buffer: &'a mut Vec<u8>,
buffer: &'a mut [u8],
data: Vec<u8>,
bits_per_channel: u8,
file_name: String,
Expand All @@ -38,7 +38,7 @@ impl<'a> Encode for RgbEncoder<'a> {
let bits = (byte >> shift) & mask;
let channel = self.buffer.next().unwrap();
*channel = (*channel & !mask) | bits;
shift = shift - (self.bits_per_channel as i32);
shift -= self.bits_per_channel as i32;
}
}

Expand Down

0 comments on commit a957705

Please sign in to comment.