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
This tries to address concerns raised in rust-lang#56 in different ways with different tradeoffs:
1. Implicit `Deref` to the underlying function pointer is replace with an explicit unsafe method `into_inner`, but in most cases it shouldn't be necessary to use.
2. Provides function `Symbol::call` which guarantees that (a) backing storage will be alive as long as it's required for calling and (b) preserves `unsafe`ty for the public interface. This is done at the cost of less convenient invocation syntax (`symbol.call(a,b,c,...)` instead of `symbol(a,b,c,...)`).
3. Provides `Symbol::into_closure` which allows to cast a `Symbol` into an opaque Rust closure. This also guarantees that the backing storage will be kept alive as long as it's required for calling, and provides a more convenient syntax (you can use normal function calls like `closure(a,b,c,...)`) at the cost of losing `unsafe` marker in the interface of the resulting function (although conversion itself still has `unsafe`). You might argue that this is unacceptable tradeoff for a public API, but, unfortunately, we don't have `UnsafeFn` family of traits yet, and also there is lots of existing precedents in stdlib that do similar "pretend that it's safe" conversions like `Box::from_raw`, `Rc::from_raw`, `slice::from_raw_parts`, `str::from_utf8_unchecked`, etc.
0 commit comments