Use const block instead of trait trick in subscription
This commit is contained in:
parent
92ecc18318
commit
2973b01bf5
1 changed files with 6 additions and 13 deletions
|
|
@ -306,7 +306,9 @@ impl<T> Subscription<T> {
|
|||
F: Fn(T) -> A + MaybeSend + Clone + 'static,
|
||||
A: 'static,
|
||||
{
|
||||
F::assert_zero_size();
|
||||
const {
|
||||
check_zero_sized::<F>();
|
||||
}
|
||||
|
||||
struct Map<A, B, F>
|
||||
where
|
||||
|
|
@ -363,7 +365,9 @@ impl<T> Subscription<T> {
|
|||
F: Fn(T) -> Option<A> + MaybeSend + Clone + 'static,
|
||||
A: MaybeSend + 'static,
|
||||
{
|
||||
F::assert_zero_size();
|
||||
const {
|
||||
check_zero_sized::<F>();
|
||||
}
|
||||
|
||||
struct FilterMap<A, B, F>
|
||||
where
|
||||
|
|
@ -522,17 +526,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
trait PanicWhenNotZeroSized: Sized {
|
||||
const _CHECK: () = check_zero_sized::<Self>();
|
||||
|
||||
#[allow(path_statements, clippy::no_effect)]
|
||||
fn assert_zero_size() {
|
||||
<Self as PanicWhenNotZeroSized>::_CHECK;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PanicWhenNotZeroSized for T {}
|
||||
|
||||
const fn check_zero_sized<T>() {
|
||||
if std::mem::size_of::<T>() != 0 {
|
||||
panic!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue