Skip to content

Commit

Permalink
Fix compile error on older rustc versions
Browse files Browse the repository at this point in the history
  • Loading branch information
KokaKiwi committed Feb 18, 2020
1 parent 78359a8 commit 4bc3e21
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Cargo.lock
# Misc stuff
.*
!.gitignore
!.travis.yml
!.gitlab-ci.yml
!.gitlab-ci-matrix.yml
!.*.toml
!.*.yaml
!.*.yml
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ impl std::error::Error for FromHexError {}
impl fmt::Display for FromHexError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::InvalidHexCharacter { c, index } => {
FromHexError::InvalidHexCharacter { c, index } => {
write!(f, "Invalid character {:?} at position {}", c, index)
}
Self::OddLength => write!(f, "Odd number of digits"),
Self::InvalidStringLength => write!(f, "Invalid string length"),
FromHexError::OddLength => write!(f, "Odd number of digits"),
FromHexError::InvalidStringLength => write!(f, "Invalid string length"),
}
}
}
Expand Down
25 changes: 6 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
//! let hex_string = hex::encode("Hello world!");
//!
//! println!("{}", hex_string); // Prints "48656c6c6f20776f726c6421"
//!
//! # assert_eq!(hex_string, "48656c6c6f20776f726c6421");
//! ```

#![doc(html_root_url = "https://docs.rs/hex/0.4.1")]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(clippy::unreadable_literal)]
#![warn(clippy::use_self)]

#[cfg(not(feature = "std"))]
extern crate alloc;
Expand All @@ -35,7 +35,7 @@ use alloc::{string::String, vec::Vec};
use core::iter;

mod error;
pub use error::FromHexError;
pub use crate::error::FromHexError;

#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
Expand Down Expand Up @@ -350,11 +350,7 @@ pub fn encode_to_slice<T: AsRef<[u8]>>(input: T, output: &mut [u8]) -> Result<()
return Err(FromHexError::InvalidStringLength);
}

for (byte, (i, j)) in input
.as_ref()
.iter()
.zip(generate_iter(input.as_ref().len() * 2))
{
for (byte, (i, j)) in input.as_ref().iter().zip(generate_iter(input.as_ref().len() * 2)) {
let (high, low) = byte2hex(*byte, HEX_CHARS_LOWER);
output[i] = high;
output[j] = low;
Expand Down Expand Up @@ -409,10 +405,7 @@ mod test {

let mut output_3 = [0; 4];

assert_eq!(
decode_to_slice(b"6", &mut output_3),
Err(FromHexError::OddLength)
);
assert_eq!(decode_to_slice(b"6", &mut output_3), Err(FromHexError::OddLength));
}

#[test]
Expand All @@ -422,10 +415,7 @@ mod test {

#[test]
fn test_decode() {
assert_eq!(
decode("666f6f626172"),
Ok(String::from("foobar").into_bytes())
);
assert_eq!(decode("666f6f626172"), Ok(String::from("foobar").into_bytes()));
}

#[test]
Expand All @@ -443,10 +433,7 @@ mod test {
#[test]
pub fn test_invalid_length() {
assert_eq!(Vec::from_hex("1").unwrap_err(), FromHexError::OddLength);
assert_eq!(
Vec::from_hex("666f6f6261721").unwrap_err(),
FromHexError::OddLength
);
assert_eq!(Vec::from_hex("666f6f6261721").unwrap_err(), FromHexError::OddLength);
}

#[test]
Expand Down

0 comments on commit 4bc3e21

Please sign in to comment.