Skip to content

Commit

Permalink
clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
harrydevnull committed Feb 8, 2017
1 parent 7556475 commit 1f1ba8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
[![crates.io version](https://img.shields.io/crates/v/cdrs.svg)](https://crates.io/crates/cdrs)

[![Coverage Status](https://coveralls.io/repos/github/harrydevnull/cdrs/badge.svg?branch=master)](https://coveralls.io/github/harrydevnull/cdrs?branch=master)
[![codecov](https://codecov.io/gh/harrydevnull/cdrs/branch/master/graph/badge.svg)](https://codecov.io/gh/harrydevnull/cdrs)


**CDRS** is a native Cassandra driver written in [Rust](https://www.rust-lang.org).
The motivation to write it in Rust is a lack of native one.
Expand Down
34 changes: 16 additions & 18 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ impl fmt::Display for CompressionError {

impl Error for CompressionError {
fn description(&self) -> &str {
let desc = match self {
match self {
&CompressionError::Snappy(ref err) => err.description(),
&CompressionError::Lz4(ref s) => s.as_str(),
};

return desc;
}
}
}

Expand Down Expand Up @@ -83,11 +81,11 @@ impl Compression {
///
/// ```
pub fn encode(&self, bytes: Vec<u8>) -> Result<Vec<u8>> {
return match self {
match self {
&Compression::Lz4 => Compression::encode_lz4(bytes),
&Compression::Snappy => Compression::encode_snappy(bytes),
&Compression::None => Ok(bytes),
};
}
}

/// It decodes `bytes` basing on type of compression.
Expand All @@ -105,32 +103,32 @@ impl Compression {
/// assert_eq!(lz4_compression.decode(input).unwrap(), bytes);
/// ```
pub fn decode(&self, bytes: Vec<u8>) -> Result<Vec<u8>> {
return match self {
match self {
&Compression::Lz4 => Compression::decode_lz4(bytes),
&Compression::Snappy => Compression::decode_snappy(bytes),
&Compression::None => Ok(bytes),
};
}
}

/// It transforms compression method into a `&str`.
pub fn as_str(&self) -> Option<&'static str> {
return match self {
match self {
&Compression::Lz4 => Some(LZ4),
&Compression::Snappy => Some(SNAPPY),
&Compression::None => None,
};
}
}

fn encode_snappy(bytes: Vec<u8>) -> Result<Vec<u8>> {
let mut encoder = snap::Encoder::new();
return encoder.compress_vec(bytes.as_slice())
.map_err(|err| CompressionError::Snappy(Box::new(err)));
encoder.compress_vec(bytes.as_slice())
.map_err(|err| CompressionError::Snappy(Box::new(err)))
}

fn decode_snappy(bytes: Vec<u8>) -> Result<Vec<u8>> {
let mut decoder = snap::Decoder::new();
return decoder.decompress_vec(bytes.as_slice())
.map_err(|err| CompressionError::Snappy(Box::new(err)));
decoder.decompress_vec(bytes.as_slice())
.map_err(|err| CompressionError::Snappy(Box::new(err)))
}

fn encode_lz4(bytes: Vec<u8>) -> Result<Vec<u8>> {
Expand All @@ -140,8 +138,8 @@ impl Compression {
fn decode_lz4(bytes: Vec<u8>) -> Result<Vec<u8>> {
// skip first 4 bytes in accordance to
// https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v4.spec#L805
return lz4::decompress(&bytes[4..])
.map_err(|err| CompressionError::Lz4(err.description().to_string()));
lz4::decompress(&bytes[4..])
.map_err(|err| CompressionError::Lz4(err.description().to_string()))
}
}

Expand All @@ -157,11 +155,11 @@ impl<'a> From<&'a str> for Compression {
/// It converts `str` into `Compression`. If string is neither `lz4` nor `snappy` then
/// `Compression::None` will be returned
fn from(compression_str: &'a str) -> Compression {
return match compression_str {
match compression_str {
LZ4 => Compression::Lz4,
SNAPPY => Compression::Snappy,
_ => Compression::None,
};
}
}
}

Expand Down

0 comments on commit 1f1ba8d

Please sign in to comment.