diff --git a/source/durandal/err.rs b/source/durandal/err.rs index da9241b..12a9fcb 100644 --- a/source/durandal/err.rs +++ b/source/durandal/err.rs @@ -37,7 +37,18 @@ macro_rules! bail { /// /// assert_eq!(format!("{}", err_msg("oh no not things")), "oh no not things"); /// ``` -pub fn err_msg(msg: &'static str) -> Error {Error::from(ErrMsg(msg))} +pub fn err_msg(msg: &'static str) -> Error {ErrMsg(msg).into()} + +/// Returns an `Error` from a `ReprError`. +/// +/// # Examples +/// +/// ``` +/// use maraiah::durandal::err::repr_error; +/// +/// assert_eq!(format!("{}", repr_error(77)), "representation error (got 77)"); +/// ``` +pub fn repr_error>(n: T) -> Error {ReprError::new(n).into()} impl ReprError { @@ -53,7 +64,7 @@ impl ReprError /// assert_eq!(format!("{}", err), "representation error (got 7)"); /// ``` #[inline] - pub fn new(n: T) -> Self where T: Into {Self(n.into())} + pub fn new>(n: T) -> Self {Self(n.into())} } impl Fail for ReprError {} diff --git a/source/marathon/defl.rs b/source/marathon/defl.rs index 89b07cc..b9f4ace 100644 --- a/source/marathon/defl.rs +++ b/source/marathon/defl.rs @@ -217,14 +217,15 @@ fn stream_dynamic(v: &mut Vec, b: &[u8], mut p: usize) -> ResultS output_tables(v, b, p, table_len, table_dst) } +#[allow(clippy::needless_range_loop)] fn stream_s_table(v: &mut Vec, b: &[u8], p: usize) -> ResultS { let mut len = [0; 288]; - for len in len.iter_mut().take(144) {*len = 8;} - for len in len.iter_mut().take(256).skip(144) {*len = 9;} - for len in len.iter_mut().take(280).skip(256) {*len = 7;} - for len in len.iter_mut().take(280).skip(288) {*len = 8;} + for i in 0..144 {len[i] = 8;} + for i in 144..256 {len[i] = 9;} + for i in 256..280 {len[i] = 7;} + for i in 280..288 {len[i] = 8;} let dst = [5; 30]; @@ -393,13 +394,13 @@ impl HuffmanTable code <<= 1; } - Err(err_msg("code not found in symbol tree")) + Err(repr_error(code)) } } struct HuffmanTable { - nums: [u8; 16], + nums: [u16; 16], syms: Vec, }