rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.77k stars 178 forks source link

Make `Dynamic::try_cast_raw` public #866

Closed paholg closed 5 months ago

paholg commented 5 months ago

This function is useful for error-reporting. With try_cast, one has to do one of the following:

  1. Pre-clone the Dynamic.
  2. Check Dynamic::is first, and still handle the None case of try_cast.
schungx commented 5 months ago

You have a better name for try_cast_raw? I tend to try to keep _raw for internal API or some really advanced API...

paholg commented 5 months ago

Fair enough. If I could go back in time, I would propose this function be try_cast and the one that returns an option be renamed or removed, but that is not worth a breaking change.

I can't think of a great name. Maybe try_cast_res or try_cast_result?

schungx commented 5 months ago

Picking a good name is important for an API, just for that reason you just mentioned -- we can never ever change it.

Let's spend a couple more days thinking up new names... there is no rush until the next release anyway...

I also think try_cast_result looks reasonable...

paholg commented 5 months ago

I have updated the name to try_cast_result.

schungx commented 5 months ago

Alright let's merge this.