Skip to content

Commit

Permalink
rust: init: broaden the blanket impl of Init
Browse files Browse the repository at this point in the history
This makes it possible to use `T` as a `impl Init<T, E>` for every error
type `E` instead of just `Infallible`.

Signed-off-by: Benno Lossin <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Reviewed-by: Martin Rodriguez Reboredo <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
  • Loading branch information
Benno Lossin authored and herrnst committed Jul 12, 2023
1 parent ee615ec commit 89f9987
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rust/kernel/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,8 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
}

// SAFETY: Every type can be initialized by-value.
unsafe impl<T> Init<T> for T {
unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible> {
unsafe impl<T, E> Init<T, E> for T {
unsafe fn __init(self, slot: *mut T) -> Result<(), E> {
unsafe { slot.write(self) };
Ok(())
}
Expand Down

0 comments on commit 89f9987

Please sign in to comment.