rhai/src/api
Nathan Kent 86d86a85e4 Remove unsound casting functions
The casting functions in `unsafe.rs` were unsound (i.e., they allowed
safe code to cause undefined behavior). While they did appear to be used
in a way that wouldn't cause UB the fact that there exists unsound
functions is unsettling.

This commit removes those functions and replaces it with a macro that
performs the same reification - the difference is that the macro call
will also include the checks which are required to prevent UB. A macro
was chosen instead of a function for two reasons:

1. A macro can keep the same code generation whereas a function would
   require going through an `Option` which has negative impacts on code
   generation (niche values cause poor DCE).
2. There exist other `unsafe` code blocks in the crate and an attempt to
   make Rhai 100% safe is completely out-of-scope for this merge
   request, so we may as well use `unsafe` in the macro.

Regarding (2) above, I may come back at a later date with a 100% safe
`reify` function but only once the other `unsafe` blocks are removed.
For posterity, said function would look something like:

```rust
fn reify<A: Any, C>(value: A) -> Option<C> {
    let mut v = Some(value);
    let v: &mut dyn Any = &mut v;
    v.downcast_mut::<Option<C>>().map(Option::take)
}
```
2022-02-05 16:29:05 -08:00
..
call_fn.rs Fix function exit trigger and add function enter trigger. 2022-02-02 22:42:33 +08:00
compile.rs Change expect("exists") to unwrap(). 2022-01-06 11:07:52 +08:00
custom_syntax.rs Remove unsound casting functions 2022-02-05 16:29:05 -08:00
deprecated.rs Use target_family for wasm. 2022-01-12 08:12:28 +08:00
eval.rs Refactor and add state to debugger. 2022-01-28 18:59:18 +08:00
events.rs Add variable definition filter. 2022-02-04 22:59:41 +08:00
files.rs Use target_family for wasm. 2022-01-12 08:12:28 +08:00
limits.rs Fix builds. 2021-12-17 16:55:07 +08:00
mod.rs Fix type name display. 2022-02-03 23:54:53 +08:00
options.rs Add allow_shadowing. 2022-02-04 13:20:47 +08:00
register.rs Gate dead code for no_module. 2022-01-29 11:09:43 +08:00
run.rs Refactor and add state to debugger. 2022-01-28 18:59:18 +08:00
type_names.rs Fix no-std build. 2022-02-04 16:38:01 +08:00