From 7760d04c8a239bc5a0befc91e95d3ac963ee14a1 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:15:49 -0400 Subject: [PATCH] io: Impl `Truncate`/`Length` for refs --- CHANGELOG.md | 4 ++++ lofty/src/util/io.rs | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bffc24356..e9756bb45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- **Truncate**: `impl Truncate for &mut T` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/384)) +- **Length**: `impl Truncate for &T` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/384)) + ## [0.19.0] - 2024-04-21 ### Added diff --git a/lofty/src/util/io.rs b/lofty/src/util/io.rs index 7b9f1f0e9..a45a98a73 100644 --- a/lofty/src/util/io.rs +++ b/lofty/src/util/io.rs @@ -89,6 +89,17 @@ where } } +impl Truncate for &mut T +where + T: Truncate, +{ + type Error = ::Error; + + fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error> { + (**self).truncate(new_len) + } +} + /// Provides a method to get the length of a storage object /// /// This is one component of the [`FileLike`] trait, which is used to provide implementors access to any @@ -154,6 +165,17 @@ where } } +impl Length for &T +where + T: Length, +{ + type Error = ::Error; + + fn len(&self) -> Result { + Length::len(*self) + } +} + /// Provides a set of methods to read and write to a file-like object /// /// This is a combination of the [`Read`], [`Write`], [`Seek`], [`Truncate`], and [`Length`] traits.