Someone from reddit suggested using impl Into<JsValue> to not have to use .into() for every argument. I spend some time experimenting and I can't figure it out. So far I only managed to use impl Into<JsValue> when all arguments are of the same type.
Yes, impl in argument position always refers to a single concrete type. Think about it like this: You need to create an array before calling the function. An array requires all it's members to have the same size for indexing to work.
Yes, impl in argument position always refers to a single concrete type. Think about it like this: You need to create an array before calling the function. An array requires all it's members to have the same size for indexing to work.
Thanks. How does .into() differs from this requirement? As I'm guessing each argument has different size
When you have ["string".into(), 0.into()], the array you construct is of type [JsValue; 2]. The first element is "string".into(), which, if you follow the definition, is JsValue::Str("string".to_owned()). Same for the 0. Each element is converted to a JsValue, and then an array is made out of them.
The code is equivalent to writing this: [JsValue::String("string".to_owned()), JsValue::Number(0)]. Each element is a JsValue so it compiles.
The two calls of into() look the same, but they refer to different methods.