-
Notifications
You must be signed in to change notification settings - Fork 9
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
Issue while with trait objects and dptree. #27
Comments
Seems strange. I think, for a fast workaround you should use just plain When I use trait objects in my bots, I wrap it into Arc<dyn finance_api::Market + Send + Sync> |
Hm, my only idea so far is that you have multiple versions of Otherwise, could you provide an MRE (minimal reproducible example)? Also as a note, you don't have to have |
I made the change, but I get an alike error message:
|
I think that I run the same version:
The implementation of the Market trait is in another library, and I checked that I only use a single version. I guess there's something odd with that implementation because I wrote a simpler example of the same idea and it works. I'll push the changes in case you can take a look. Anyway, thanks for the help! |
Hi, I tried to rewrite a little bit of the code and I still get the same issue. I'm going to get rid of the trait stuff, and directly include the implementation that I need from my other library into the telegram bot. I need to move forward, and I'll get back to this later to properly use my external lib. Thanks for the help, whenever I have any update and all the code is pushed, I'll update this issue. |
@felipet can you provide a link to your code that would allow us to debug the issue?... |
Sure @WaffleLapkin . Sorry for the delay, I wanted to tidy up the code so it would be easier to read. You can download the code for the bot from here: shortbot. In brief, the code it diverges from works. The main change I made respect to my previous code is that I copied the code from the lib Then, you'll need a dirty step, which is to clone locally one dep: finance_ibex, and apply the attached patch to modify the code and make it async-compatible. I'm reluctant to push it because I made those changes quickly to see if it would work or not. As it didn't, I postpone doing it properly until I have more time. To replicate the issue, just export a token for a telegram API using this variable:
Then run the app. If you run the bot's command |
@felipet are you sure the code in the branch still produces the same error?.. The handler has |
Also re: reproduce steps ... that is a bit much. Generally it is expected that the big reporter creates a MRE/minimization so that it's easy for other people to reproduce. Cloning another dep and patching it with a zip is more effort than I'm ready to do.... Btw your repo also does not contain a |
@WaffleLapkin yeah sorry for the code, it's not actually generating exactly the same error right now. About the way to reproduce the error and so, as I said, I'll push the code once it's ready. I asked initially just to know if there was any limitation that you'd know about the use of traits in this particular scenario. Since you asked for the code even when I said that I'll post it once it's ready, I tried to push something for you. I was not expecting you to fix anything, I was just asking in case there was any limitation about using trait objects along dependencies of the dispatcher. Given that you didn't mention it exists, please give me some time to rework that code once I have more time for it. Using a trait object is not my priority right now, so I took a particular implementation of the trait to continue with the other features that have a higher level of priority. About the Thanks once again. |
@felipet no worries. your original error looked like a bug in teloxide (since it fossils that the type is not there and then mentions the same type), so I wanted to see if it really is a bug in teloxide. And that wouldn't require you to change code, since you did get the error already, so you could literally take the code as-is and it would reproduce the error (and then maybe remove some things to minimize the example). But either way, if you are not interested, then don't sweat :)
That doesn't really work?... In the sense that if a dependency is updated to a semver compatible version, cargo will use the new version, potentially changing things. Even if you use |
Thanks @WaffleLapkin for the explanation regarding Regarding the old code, I was stuck with that issue for a few weeks, and when I got feed up with it, I simply wiped it and reimplemented the code without traits. The v0.1 doesn't support async code, and that's why those changes that provoked the issue are gone. The idea behind the trait is to allow more stock markets in the future, which is really very unlikely to happen. So I ended kicking out the trait and using straight a particular implementation. It's a nice to have thing, so as soon as I have time to prepare the code and properly describe the issue I'll do it. |
Hi again @WaffleLapkin , I wrote a simple code example that reproduces the issue. Please, check the code out of here. The steps to reproduce the issue are listed in the README file. I simplified the code example: I defined a struct which holds an |
Hey. I've just tried your example out. So, the problem is solved by:
So, dynamic dispatching and types are tricky, because previously your data had type Just do the type conversion |
Thanks @syrtcevvi for the solution. I didn't consider the casting because the compiler accepted the code. |
Note that this is a separate issue, since the error should have said that the context has |
Hi, I'm trying to pass a trait object as a dependency of the
Dispatcher::builder
and I can't figure out what I'm doing wrong with it because I get a runtime panick asking for the same type that I seem to be providing:The text was updated successfully, but these errors were encountered: