From 8f7f8afc3569f7e732e879479666da2daa2366c5 Mon Sep 17 00:00:00 2001 From: KAMADA Ken'ichi Date: Sat, 3 Apr 2021 23:34:25 +0900 Subject: [PATCH] Remove AnnotatableTryInto and cleanup the uses of TryFrom. --- src/isobmff.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/isobmff.rs b/src/isobmff.rs index 3f7fef0..c80bbce 100644 --- a/src/isobmff.rs +++ b/src/isobmff.rs @@ -24,6 +24,7 @@ // SUCH DAMAGE. // +use std::convert::{TryFrom as _, TryInto as _}; use std::io::{BufRead, ErrorKind, Seek, SeekFrom}; use crate::endian::{Endian, BigEndian}; @@ -45,15 +46,6 @@ impl From<&'static str> for Error { } } -trait AnnotatableTryInto { - fn try_into(self) -> Result - where Self: std::convert::TryInto { - std::convert::TryInto::try_into(self) - } -} - -impl AnnotatableTryInto for T where T: From {} - pub fn get_exif_attr(reader: &mut R) -> Result, Error> where R: BufRead + Seek { let mut parser = Parser::new(reader); @@ -140,8 +132,7 @@ impl Parser where R: BufRead + Seek { 1 => read64(&mut self.reader)?.checked_sub(16), x => u64::from(x).checked_sub(8), }.ok_or("Invalid box size")?; - let boxtype = std::convert::TryFrom::try_from(&buf[4..8]) - .expect("never happen"); + let boxtype = buf[4..8].try_into().expect("never fails"); Ok(Some((size, boxtype))) } @@ -376,7 +367,7 @@ impl<'a> BoxSplitter<'a> { let boxtype = self.slice(4)?; let body_len = match size { 0 => Some(self.len()), - 1 => self.uint64()?.try_into::() + 1 => usize::try_from(self.uint64()?) .or(Err("Box is larger than the address space"))? .checked_sub(16), _ => size.checked_sub(8), @@ -414,8 +405,7 @@ impl<'a> BoxSplitter<'a> { } fn array4(&mut self) -> Result<[u8; 4], Error> { - self.slice(4).map(|x| std::convert::TryFrom::try_from(x) - .expect("never happen")) + self.slice(4).map(|x| x.try_into().expect("never fails")) } fn slice(&mut self, at: usize) -> Result<&'a [u8], Error> {