1
Fork 0

Use PhantomData directly in Bridge

This commit is contained in:
bjorn3 2022-04-06 18:53:19 +02:00
parent 6eab9802c9
commit 7eda975b06
2 changed files with 11 additions and 3 deletions

View file

@ -220,8 +220,6 @@ use rpc::{Decode, DecodeMut, Encode, Reader, Writer};
/// then passes it to the client through the function pointer in the `run`
/// field of `client::Client`. The client holds its copy of the `Bridge`
/// in TLS during its execution (`Bridge::{enter, with}` in `client.rs`).
// Note: Bridge is !Send and !Sync due to containg a `Closure`. If this
// ever changes, make sure to preserve the !Send and !Sync property.
#[repr(C)]
pub struct Bridge<'a> {
/// Reusable buffer (only `clear`-ed, never shrunk), primarily
@ -233,6 +231,9 @@ pub struct Bridge<'a> {
/// If 'true', always invoke the default panic hook
force_show_panics: bool,
// Prevent Send and Sync impls
_marker: marker::PhantomData<*mut ()>,
}
#[forbid(unsafe_code)]

View file

@ -153,7 +153,12 @@ impl ExecutionStrategy for SameThread {
let mut dispatch = |b| dispatcher.dispatch(b);
run_client(
Bridge { cached_buffer: input, dispatch: (&mut dispatch).into(), force_show_panics },
Bridge {
cached_buffer: input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
},
client_data,
)
}
@ -189,6 +194,7 @@ impl ExecutionStrategy for CrossThread1 {
cached_buffer: input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
},
client_data,
)
@ -241,6 +247,7 @@ impl ExecutionStrategy for CrossThread2 {
cached_buffer: input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
},
client_data,
);