Skip to content

Commit

Permalink
io: Impl Truncate/Length for refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Apr 26, 2024
1 parent f17bac4 commit 120b5f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions lofty/src/util/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 120b5f5

Please sign in to comment.