Skip to content

Commit 8bb6c50

Browse files
authored
inout: add InOut::into_out and InOutBufReserved::into_out (#1132)
1 parent 32842f6 commit 8bb6c50

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

inout/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Migrated from `generic-array` to `hybrid-array` ([#944])
1010
- MSRV is bumped to 1.81 ([#1116])
1111

12+
### Added
13+
- `InOut::into_out` and `InOutBufReserved::into_out` methods ([#1132])
14+
1215
[#944]: https://github.com/RustCrypto/utils/pull/944
1316
[#1116]: https://github.com/RustCrypto/utils/pull/1116
17+
[#1132]: https://github.com/RustCrypto/utils/pull/1132
1418

1519
## 0.1.3 (2022-03-31)
1620
### Fixed

inout/src/inout.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ impl<'inp, 'out, T> InOut<'inp, 'out, T> {
3333
unsafe { &mut *self.out_ptr }
3434
}
3535

36+
/// Consume `self` and get mutable reference to the output value with lifetime `'out`.
37+
#[inline(always)]
38+
pub fn into_out(self) -> &'out mut T {
39+
unsafe { &mut *self.out_ptr }
40+
}
41+
3642
/// Convert `self` to a pair of raw input and output pointers.
3743
#[inline(always)]
3844
pub fn into_raw(self) -> (*const T, *mut T) {

inout/src/inout_buf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'inp, 'out, T> InOutBuf<'inp, 'out, T> {
121121
unsafe { slice::from_raw_parts_mut(self.out_ptr, self.len) }
122122
}
123123

124-
/// Consume self and return output slice with lifetime `'a`.
124+
/// Consume `self` and get output slice with lifetime `'out`.
125125
#[inline(always)]
126126
pub fn into_out(self) -> &'out mut [T] {
127127
unsafe { slice::from_raw_parts_mut(self.out_ptr, self.len) }

inout/src/reserved.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ impl<'inp, 'out, T> InOutBufReserved<'inp, 'out, T> {
124124
pub fn get_out<'a>(&'a mut self) -> &'a mut [T] {
125125
unsafe { slice::from_raw_parts_mut(self.out_ptr, self.out_len) }
126126
}
127+
128+
/// Consume `self` and get output slice with lifetime `'out`.
129+
#[inline(always)]
130+
pub fn into_out(self) -> &'out mut [T] {
131+
unsafe { slice::from_raw_parts_mut(self.out_ptr, self.out_len) }
132+
}
127133
}
128134

129135
impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> {

0 commit comments

Comments
 (0)