Skip to content

Commit

Permalink
inout: add InOut::into_out and InOutBufReserved::into_out (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Nov 20, 2024
1 parent 32842f6 commit 8bb6c50
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions inout/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Migrated from `generic-array` to `hybrid-array` ([#944])
- MSRV is bumped to 1.81 ([#1116])

### Added
- `InOut::into_out` and `InOutBufReserved::into_out` methods ([#1132])

[#944]: https://github.com/RustCrypto/utils/pull/944
[#1116]: https://github.com/RustCrypto/utils/pull/1116
[#1132]: https://github.com/RustCrypto/utils/pull/1132

## 0.1.3 (2022-03-31)
### Fixed
Expand Down
6 changes: 6 additions & 0 deletions inout/src/inout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ impl<'inp, 'out, T> InOut<'inp, 'out, T> {
unsafe { &mut *self.out_ptr }
}

/// Consume `self` and get mutable reference to the output value with lifetime `'out`.
#[inline(always)]
pub fn into_out(self) -> &'out mut T {
unsafe { &mut *self.out_ptr }
}

/// Convert `self` to a pair of raw input and output pointers.
#[inline(always)]
pub fn into_raw(self) -> (*const T, *mut T) {
Expand Down
2 changes: 1 addition & 1 deletion inout/src/inout_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'inp, 'out, T> InOutBuf<'inp, 'out, T> {
unsafe { slice::from_raw_parts_mut(self.out_ptr, self.len) }
}

/// Consume self and return output slice with lifetime `'a`.
/// Consume `self` and get output slice with lifetime `'out`.
#[inline(always)]
pub fn into_out(self) -> &'out mut [T] {
unsafe { slice::from_raw_parts_mut(self.out_ptr, self.len) }
Expand Down
6 changes: 6 additions & 0 deletions inout/src/reserved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ impl<'inp, 'out, T> InOutBufReserved<'inp, 'out, T> {
pub fn get_out<'a>(&'a mut self) -> &'a mut [T] {
unsafe { slice::from_raw_parts_mut(self.out_ptr, self.out_len) }
}

/// Consume `self` and get output slice with lifetime `'out`.
#[inline(always)]
pub fn into_out(self) -> &'out mut [T] {
unsafe { slice::from_raw_parts_mut(self.out_ptr, self.out_len) }
}
}

impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> {
Expand Down

0 comments on commit 8bb6c50

Please sign in to comment.