Skip to content

Commit 4bc3e21

Browse files
committed
Fix compile error on older rustc versions
1 parent 78359a8 commit 4bc3e21

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Cargo.lock
55
# Misc stuff
66
.*
77
!.gitignore
8-
!.travis.yml
9-
!.gitlab-ci.yml
10-
!.gitlab-ci-matrix.yml
8+
!.*.toml
9+
!.*.yaml
10+
!.*.yml

src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ impl std::error::Error for FromHexError {}
2323
impl fmt::Display for FromHexError {
2424
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2525
match *self {
26-
Self::InvalidHexCharacter { c, index } => {
26+
FromHexError::InvalidHexCharacter { c, index } => {
2727
write!(f, "Invalid character {:?} at position {}", c, index)
2828
}
29-
Self::OddLength => write!(f, "Odd number of digits"),
30-
Self::InvalidStringLength => write!(f, "Invalid string length"),
29+
FromHexError::OddLength => write!(f, "Odd number of digits"),
30+
FromHexError::InvalidStringLength => write!(f, "Invalid string length"),
3131
}
3232
}
3333
}

src/lib.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
//! let hex_string = hex::encode("Hello world!");
1919
//!
2020
//! println!("{}", hex_string); // Prints "48656c6c6f20776f726c6421"
21+
//!
2122
//! # assert_eq!(hex_string, "48656c6c6f20776f726c6421");
2223
//! ```
2324
2425
#![doc(html_root_url = "https://docs.rs/hex/0.4.1")]
2526
#![cfg_attr(not(feature = "std"), no_std)]
2627
#![cfg_attr(docsrs, feature(doc_cfg))]
2728
#![allow(clippy::unreadable_literal)]
28-
#![warn(clippy::use_self)]
2929

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

3737
mod error;
38-
pub use error::FromHexError;
38+
pub use crate::error::FromHexError;
3939

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

353-
for (byte, (i, j)) in input
354-
.as_ref()
355-
.iter()
356-
.zip(generate_iter(input.as_ref().len() * 2))
357-
{
353+
for (byte, (i, j)) in input.as_ref().iter().zip(generate_iter(input.as_ref().len() * 2)) {
358354
let (high, low) = byte2hex(*byte, HEX_CHARS_LOWER);
359355
output[i] = high;
360356
output[j] = low;
@@ -409,10 +405,7 @@ mod test {
409405

410406
let mut output_3 = [0; 4];
411407

412-
assert_eq!(
413-
decode_to_slice(b"6", &mut output_3),
414-
Err(FromHexError::OddLength)
415-
);
408+
assert_eq!(decode_to_slice(b"6", &mut output_3), Err(FromHexError::OddLength));
416409
}
417410

418411
#[test]
@@ -422,10 +415,7 @@ mod test {
422415

423416
#[test]
424417
fn test_decode() {
425-
assert_eq!(
426-
decode("666f6f626172"),
427-
Ok(String::from("foobar").into_bytes())
428-
);
418+
assert_eq!(decode("666f6f626172"), Ok(String::from("foobar").into_bytes()));
429419
}
430420

431421
#[test]
@@ -443,10 +433,7 @@ mod test {
443433
#[test]
444434
pub fn test_invalid_length() {
445435
assert_eq!(Vec::from_hex("1").unwrap_err(), FromHexError::OddLength);
446-
assert_eq!(
447-
Vec::from_hex("666f6f6261721").unwrap_err(),
448-
FromHexError::OddLength
449-
);
436+
assert_eq!(Vec::from_hex("666f6f6261721").unwrap_err(), FromHexError::OddLength);
450437
}
451438

452439
#[test]

0 commit comments

Comments
 (0)