You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Although this would be less future-proof than the current implementation, a #![no_std] compatable backend for this crate could be provided by a transmute implementation like this one (using fake_static)
#![forbid(unsafe_code)]#![no_std]use core::cell::{Cell,UnsafeCell};// may want to just depend on fake_static? instead of re-definingfnhelper<'a,'b,T>(_:&'a &'b (),v:&'b T) -> &'a T{ v }/// Use black magic fuckery to turn any `&T` into a `&'static T`./// May introduce undefined behavior.pubfnmake_static<'a,T>(input:&'a T) -> &'static T{let f:fn(_,&'a T) -> &'static T = helper;f(&&(), input)}pubfntransmute<T,U:'static>(e:T) -> U{// Store a None `U` value and get a reference to it:letmut value:Result<Cell<Option<UnsafeCell<U>>>,Cell<Option<UnsafeCell<T>>>> = Ok(Cell::new(None));let u_ref:&Cell<Option<UnsafeCell<U>>> = ifletOk(v) = &value {make_static(v)}else{unreachable!()};// Store a Some `T` value:
value = Err(Cell::new(Some(UnsafeCell::new(e))));// Use our previous `U` reference to access the stored `T` value:
u_ref.take().unwrap().into_inner()}
concerns
too powerfull to be left alive
may require the addition of a MSRV (maximum supported rust version)
code readability
The text was updated successfully, but these errors were encountered:
Although this would be less future-proof than the current implementation, a
#![no_std]
compatable backend for this crate could be provided by a transmute implementation like this one (using fake_static)concerns
code readabilityThe text was updated successfully, but these errors were encountered: