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
There are cases where type inference is impossible, even when fully qualified paths to every method/function is given. In those cases the macro author need to specify the type.
Consider this function:
In this case it can't infer the type of __v0, since it can't know what the Self type of FromStr is. This instance could be fixed if we allowed specifying the Self type. We could then change the first line to:
let __v0 = <::std::string::Stringas::std::str::FromStr>::from_str("str");
A separate issue can arise if we invoke a trait function with generic parameters, and one of the parameters needs to be specified.
I'm not sure what would be a good interface to deal with this issue. We might generate INVOKE_WITH_SELF. where the first parameter is a Type or RuntimeType parameter, and the rest works like regular INVOKE. We might alternatively have a set_self function that deals with this, that can be used after a normal INVOKE. Unfortunately, this only deals with the Self issue, and not generics in general.
Any suggestions here would be helpful.
The text was updated successfully, but these errors were encountered:
I think this can happen much later, as part of gradually expanding the scope of macros that reflect is suitable for. In the early stage I think it's fine to focus on just simple macros like Debug where very basic inference is enough to generate correct code. Once we have a robust solution there, we can move on to the more complex use cases.
For a possible API for manual type info, we could support specifying the type of any Value as needed, and the types of a function's generic parameters and Self type.
let result = RUNTIME::std::str::FromStr::from_str.INVOKE(input);let value = RUNTIME::std::result::Result::unwrap.INVOKE(result);
value.set_type(my_field.get_type());// fn set_type(&self, ty: reflect::Type)
// for a function like `fn huh<A, B, C>(arg: D)`// where set_type isn't sufficient to determine all the parameters:RUNTIME::path::to::huh
.generic(type_a, type_b, type_c).INVOKE(value_d);
// to get `<::std::string::String as ::std::str::FromStr>::from_str(input)`RUNTIME::std::str::FromStr::from_str
.impl_for(RUNTIME::std::string::String).INVOKE(input);
There are cases where type inference is impossible, even when fully qualified paths to every method/function is given. In those cases the macro author need to specify the type.
Consider this function:
In this case it can't infer the type of __v0, since it can't know what the Self type of FromStr is. This instance could be fixed if we allowed specifying the Self type. We could then change the first line to:
A separate issue can arise if we invoke a trait function with generic parameters, and one of the parameters needs to be specified.
I'm not sure what would be a good interface to deal with this issue. We might generate
INVOKE_WITH_SELF
. where the first parameter is a Type or RuntimeType parameter, and the rest works like regularINVOKE
. We might alternatively have aset_self
function that deals with this, that can be used after a normalINVOKE
. Unfortunately, this only deals with the Self issue, and not generics in general.Any suggestions here would be helpful.
The text was updated successfully, but these errors were encountered: