From 4bc3e21f7976b8fa39a5fe62b06b6443810dc2c2 Mon Sep 17 00:00:00 2001 From: KokaKiwi Date: Tue, 18 Feb 2020 17:36:14 +0100 Subject: [PATCH] Fix compile error on older rustc versions --- .gitignore | 6 +++--- src/error.rs | 6 +++--- src/lib.rs | 25 ++++++------------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 941ffc5..4132a04 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,6 @@ Cargo.lock # Misc stuff .* !.gitignore -!.travis.yml -!.gitlab-ci.yml -!.gitlab-ci-matrix.yml +!.*.toml +!.*.yaml +!.*.yml diff --git a/src/error.rs b/src/error.rs index c65474f..b9f2acf 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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"), } } } diff --git a/src/lib.rs b/src/lib.rs index a98c2a3..2cfc345 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ //! let hex_string = hex::encode("Hello world!"); //! //! println!("{}", hex_string); // Prints "48656c6c6f20776f726c6421" +//! //! # assert_eq!(hex_string, "48656c6c6f20776f726c6421"); //! ``` @@ -25,7 +26,6 @@ #![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; @@ -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")))] @@ -350,11 +350,7 @@ pub fn encode_to_slice>(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; @@ -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] @@ -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] @@ -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]