From 3a8f11450f056d705911c1aa8ce47b6e6d212f0b Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Wed, 13 Jul 2022 11:44:53 -0700 Subject: [PATCH] clippy cleanup on client example --- examples/client/src/mp4.rs | 23 ++++++++++------------- examples/client/src/onvif.rs | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/examples/client/src/mp4.rs b/examples/client/src/mp4.rs index 27641dd..534ac79 100644 --- a/examples/client/src/mp4.rs +++ b/examples/client/src/mp4.rs @@ -80,13 +80,13 @@ pub struct Opts { macro_rules! write_box { ($buf:expr, $fourcc:expr, $b:block) => {{ let _: &mut BytesMut = $buf; // type-check. - let pos_start = $buf.len(); + let pos_start = ($buf as &BytesMut).len(); let fourcc: &[u8; 4] = $fourcc; $buf.extend_from_slice(&[0, 0, 0, 0, fourcc[0], fourcc[1], fourcc[2], fourcc[3]]); let r = { $b; }; - let pos_end = $buf.len(); + let pos_end = ($buf as &BytesMut).len(); let len = pos_end.checked_sub(pos_start).unwrap(); $buf[pos_start..pos_start + 4].copy_from_slice(&u32::try_from(len)?.to_be_bytes()[..]); r @@ -305,7 +305,7 @@ impl Mp4Writer { .seek(SeekFrom::Start(u64::from(self.mdat_start - 8))) .await?; self.inner - .write_all(&u32::try_from(self.mdat_pos + 8 - self.mdat_start)?.to_be_bytes()[..]) + .write_all(&(self.mdat_pos + 8 - self.mdat_start).to_be_bytes()[..]) .await?; Ok(()) } @@ -462,9 +462,9 @@ impl Mp4Writer { buf.put_u32(0); // version buf.put_u32(1); // entry_count buf.extend_from_slice( - ¶meters + parameters .sample_entry() - .expect("all added streams have sample entries")[..], + .expect("all added streams have sample entries"), ); }); self.audio_trak.write_common_stbl_parts(buf)?; @@ -580,8 +580,7 @@ impl Mp4Writer { .checked_add(size) .ok_or_else(|| anyhow!("mdat_pos overflow"))?; if frame.is_random_access_point() { - self.video_sync_sample_nums - .push(u32::try_from(self.video_trak.samples)?); + self.video_sync_sample_nums.push(self.video_trak.samples); } self.inner.write_all(frame.data()).await?; Ok(()) @@ -663,8 +662,8 @@ async fn copy<'a>( } /// Writes the `.mp4`, including trying to finish or clean up the file. -async fn write_mp4<'a>( - opts: &'a Opts, +async fn write_mp4( + opts: &Opts, session: retina::client::Session, audio_params: Option>, stop_signal: Pin>>>, @@ -694,10 +693,8 @@ async fn write_mp4<'a>( if let Err(e) = tokio::fs::remove_file(&tmp_filename).await { log::error!("and removing .mp4 failed too: {}", e); } - } else { - if let Err(e) = tokio::fs::rename(&tmp_filename, &opts.out).await { - log::error!("unable to move completed .mp4 into place: {}", e); - } + } else if let Err(e) = tokio::fs::rename(&tmp_filename, &opts.out).await { + log::error!("unable to move completed .mp4 into place: {}", e); } Err(e) } else { diff --git a/examples/client/src/onvif.rs b/examples/client/src/onvif.rs index 2d49467..35e8e12 100644 --- a/examples/client/src/onvif.rs +++ b/examples/client/src/onvif.rs @@ -62,7 +62,7 @@ async fn run_inner(opts: Opts, session_group: Arc) -> Result<(), E info!( "{}: {}\n", &m.timestamp(), - std::str::from_utf8(&m.data()[..]).unwrap(), + std::str::from_utf8(m.data()).unwrap(), ); }, _ => continue,