Skip to content

Commit

Permalink
Add repr(transparent) to hyper_context
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Dec 20, 2023
1 parent 1d4ff35 commit 293df63
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ffi/task.rs
Expand Up @@ -127,6 +127,7 @@ struct TaskFuture {
/// its only purpose is to provide access to the waker. See `hyper_waker`.
///
/// Corresponding Rust type: <https://doc.rust-lang.org/std/task/struct.Context.html>
#[repr(transparent)] // we transmute references
pub struct hyper_context<'a>(Context<'a>);

/// A waker that is saved and used to waken a pending task.
Expand Down Expand Up @@ -500,7 +501,7 @@ where

impl hyper_context<'_> {
pub(crate) fn wrap<'a, 'b>(cx: &'a mut Context<'b>) -> &'a mut hyper_context<'b> {
// A struct with only one field has the same layout as that field.
// A repr(transparent) struct has the same layout its dataful field.
unsafe { std::mem::transmute::<&mut Context<'_>, &mut hyper_context<'_>>(cx) }
}
}
Expand Down

0 comments on commit 293df63

Please sign in to comment.