From d213bba502043aac09a0bdb845278a53ea04f600 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Tue, 6 Aug 2019 17:52:16 -0400 Subject: WIP: stalled out trying to implement const-fn feature. Unfortunately, to maintain API compatibility, `replace` needs to be a regular borrow, so we need interior mutability with `UnsafeCell`. Simultaneously, `HandlerArray` needs to be `const fn` so it can be used where `lazy_static` isn't available, which means it needs to initialize its array in one go without the help of `MaybeUninit`. To do that, `Handler` must be `Copy`, but since it contains an `UnsafeCell` now, it cannot be copy. And thus we are boned. There are times when I think the premise of rust is admirable, but implementation is impossible. --- src/fnnop.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/fnnop.rs') diff --git a/src/fnnop.rs b/src/fnnop.rs index 871a6ab..13b9379 100644 --- a/src/fnnop.rs +++ b/src/fnnop.rs @@ -2,6 +2,7 @@ // //#![feature(unboxed_closures)] //#![feature(fn_traits)] +use core::cell::UnsafeCell; pub struct FnNOP(); @@ -16,4 +17,4 @@ impl FnOnce<()> for FnNOP { extern "rust-call" fn call_once(self, _args: ()) {} } -static mut NOP: FnNOP = FnNOP(); +pub static mut NOP: UnsafeCell = UnsafeCell::new(FnNOP()); -- cgit v1.2.3