evcxr / evcxr

Other
5.59k stars 216 forks source link

Invalid code generation when no tokio dependency is added #355

Open schitcrafter opened 11 months ago

schitcrafter commented 11 months ago

Description

When there is no tokio dependency specified, but async code is in use, evcxr automatically adds tokio = "1.20.1" to the generated Cargo.toml. In the generated lib.rs, a new tokio runtime is then created, using tokio::runtime::Runtime::new(..) - this method, however, is only available on the "rt-multi-thread" feature (see here). Trying to execute this (in my case, inside a jupyter notebook) leads to a strange error:

no function or associated item named `new` found for struct `Runtime` in the current scope

Possible solutions

Automatically add the "rt-multi-thread" or "full" feature when generating Cargo.toml

Local Setup

evcxr v0.16.0, rust 1.74.0, Windows 11

schitcrafter commented 11 months ago

Kinda unrelated but I just wanna mention that there's not a lot of documentation on how to use async with evcxr - I'd find it very good to have some info on what I need to do/what is done automatically

davidlattimore commented 11 months ago

Thanks for the bug reports! I've pushed fixes for those issues. I had some documentation the sample notebook for the jupyter kernel, but that's a super-not-obvious place to look. I took those docs and adapted / updated them and put them in COMMON.md.