Closed gauteh closed 4 months ago
Ref, need blocking Write on rp-hal: https://github.com/rp-rs/rp-hal/issues/760 , should probably just upgrade to eh-1.
Finally got the time to make some effort on this. Think it is getting closer now. The pi-pico example is going to fail until the blocking write trait is implemented, or we upgrade to eh-1 (#11).
The current approach is unsound for two reasons:
&mut T
, then while it is live you dereference the aliasing pointer to perform defmt actions. This violates safety rules of exclusive references. If you would like to keep the handle around just to enforce the lifetime, you can usePhantomData<&'a mut T>
instead, which will keep the lifetime check without keeping a second, aliased reference.mem::forget()
the handle, ending the lifetime without running the destructor, and then allowing for aliased behavior.Additionally, using the unsafe
serial
fn is UB any defmt behavior occurs while you are holding the reference.I'm also not sure why the transmute is necessary to go from
&mut dyn EraseWrite
to*mut dyn EraseWrite
.