io: Impl Truncate/Length for refs

This commit is contained in:
Serial 2024-04-26 08:15:49 -04:00 committed by Alex
parent f17bac49b3
commit 120b5f52cb
2 changed files with 26 additions and 0 deletions

View file

@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- **Truncate**: `impl<T: Truncate> Truncate for &mut T` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/384))
- **Length**: `impl<T: Length> Truncate for &T` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/384))
## [0.19.0] - 2024-04-21
### Added

View file

@ -89,6 +89,17 @@ where
}
}
impl<T> Truncate for &mut T
where
T: Truncate,
{
type Error = <T as Truncate>::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<T> Length for &T
where
T: Length,
{
type Error = <T as Length>::Error;
fn len(&self) -> Result<u64, Self::Error> {
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.