Skip to content

Commit 120b5f5

Browse files
committed
io: Impl Truncate/Length for refs
1 parent f17bac4 commit 120b5f5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
- **Truncate**: `impl<T: Truncate> Truncate for &mut T` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/384))
11+
- **Length**: `impl<T: Length> Truncate for &T` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/384))
12+
913
## [0.19.0] - 2024-04-21
1014

1115
### Added

lofty/src/util/io.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ where
8989
}
9090
}
9191

92+
impl<T> Truncate for &mut T
93+
where
94+
T: Truncate,
95+
{
96+
type Error = <T as Truncate>::Error;
97+
98+
fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error> {
99+
(**self).truncate(new_len)
100+
}
101+
}
102+
92103
/// Provides a method to get the length of a storage object
93104
///
94105
/// This is one component of the [`FileLike`] trait, which is used to provide implementors access to any
@@ -154,6 +165,17 @@ where
154165
}
155166
}
156167

168+
impl<T> Length for &T
169+
where
170+
T: Length,
171+
{
172+
type Error = <T as Length>::Error;
173+
174+
fn len(&self) -> Result<u64, Self::Error> {
175+
Length::len(*self)
176+
}
177+
}
178+
157179
/// Provides a set of methods to read and write to a file-like object
158180
///
159181
/// This is a combination of the [`Read`], [`Write`], [`Seek`], [`Truncate`], and [`Length`] traits.

0 commit comments

Comments
 (0)