-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ToTypename
for Result
#86
Comments
I'll have to check how Result<T,E> gets turned into a lua value but without having looked into it yet I fear that just implementing ToTypename is not good enough (and even if it is, that the resulting .d.tl files that use it will not work) edit: Probably a good idea to explain why the .d.tl file won't work. Basically, I expect that it becomes a structure that boils down to |
The result gets turned into one or two values: |
that.... is not a nice type to work with >_< it means that the type actually is a So, we have to simplify it until it is valid. Which will get us And this will work.... until it doesn't. Because, once again, tuples. If you return a Even worse, |
Yeah, I'm not sure how they want to handle it when you return a result and something else. It's not well defined in Lua either, what is the interface when you return 3 values but also potentially an error? Sometimes you have to reach for instanceof (or typeof or however it's called). I think they have an escape hatch: Anything that implements IntoLua implements IntoLuaMulti (potentially gets converted to several values). If you want something more complex as a customer, you can make your own type that contains a Result and a F (and G, ...) and implement yourself IntoLuaMulti and FromLua, deciding on the API at that point. |
mlua solves another issue than the one I run into. Mlua just wants to make sure that a given value can be converted into a lua value. And a The problematic part comes from writing the correct type. Lua, has no tuples. So, there is no way to write However, once the sides become unbalanced, which is the case with Result<T,E> it becomes very messy. I still think I will implement |
AFAIU you can't write EDIT: Oh, interesting, you can write |
With
mlua
,Result
implementsIntoLuaMulti
(as long as the arguments implementIntoLua
). However, that breaks with tealr since it doesn't implementToTypename
. And we can't implement it in a client crate, since we own neither the struct nor the trait.Could you implement
ToTypename
forResult
?The text was updated successfully, but these errors were encountered: