rust - Rust Playground和本地计算机中reqwest示例的错误

标签 rust async-await rust-tokio reqwest

我把 reqwest 库弄得一团糟,并想用 Rust Playground 尝试一些示例。我已经从网络上获取了最简单的示例之一,但是它没有编译。
请点击下面的链接,然后点击运行:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fb0e7911a018ddb927cb13debd34fff4
这是控制台中显示的编译错误:

   Compiling playground v0.0.1 (/playground)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-Wl,--eh-frame-hdr" "-L" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/playground/target/debug/deps/playground-552f473283bcb85e.playground.1fpw7zol-cgu.0.rcgu.o" "-o" "/playground/target/debug/deps/playground-552f473283bcb85e" "/playground/target/debug/deps/playground-552f473283bcb85e.4jwju6fs7xga1d77.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/playground/target/debug/deps" "-L" "/playground/target/debug/build/libsqlite3-sys-16200be2df74876c/out" "-L" "/playground/target/debug/build/ring-bb20fb99fa6aa7fb/out" "-L" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/playground/target/debug/deps/libfutures-e81e955c63e30b74.rlib" "/playground/target/debug/deps/libfutures_executor-cfdeba081d488308.rlib" "/playground/target/debug/deps/libreqwest-f9a05f7baf6db60c.rlib" "/playground/target/debug/deps/libcookie_store-140640047f1ead84.rlib" "/playground/target/debug/deps/libpublicsuffix-6ec6805d8d4576ca.rlib" "/playground/target/debug/deps/libregex-690a57b3d88f2f3e.rlib" "/playground/target/debug/deps/libthread_local-8d339f961a8cde82.rlib" "/playground/target/debug/deps/libregex_syntax-4b763771453cb6c9.rlib" "/playground/target/debug/deps/libaho_corasick-a90058961ca40ce7.rlib" "/playground/target/debug/deps/liberror_chain-bfc8e31e68aab259.rlib" "/playground/target/debug/deps/libbacktrace-1f6305b7986130af.rlib" "/playground/target/debug/deps/libobject-8fae803afce7a82f.rlib" "/playground/target/debug/deps/libaddr2line-4cb58e132c263024.rlib" "/playground/target/debug/deps/libobject-600bcc9a4024c890.rlib" "/playground/target/debug/deps/libflate2-7c0dda569caa75f2.rlib" "/playground/target/debug/deps/libminiz_oxide-06fcba964606bf52.rlib" "/playground/target/debug/deps/libadler-cf7f582a580fb2a1.rlib" "/playground/target/debug/deps/libcrc32fast-d8f8d6d441eb6dc8.rlib" "/playground/target/debug/deps/libwasmparser-18775bada4336335.rlib" "/playground/target/debug/deps/libgimli-e397da103aee7023.rlib" "/playground/target/debug/deps/libstable_deref_trait-33402efe82680c8b.rlib" "/playground/target/debug/deps/libfallible_iterator-2abec6be3aaf9504.rlib" "/playground/target/debug/deps/libcpp_demangle-af0e508f637e754e.rlib" "/playground/target/debug/deps/librustc_demangle-b0887c2590d815fd.rlib" "/playground/target/debug/deps/libcookie-212b7aa8adce5158.rlib" "/playground/target/debug/deps/libtime-fd9f56ac09845820.rlib" "/playground/target/debug/deps/libtime_macros-a8c33e90ea2139d7.rlib" "/playground/target/debug/deps/libstandback-f34bd7ec31cc9868.rlib" "/playground/target/debug/deps/libhyper_tls-9848d4b1ee8e7a27.rlib" "/playground/target/debug/deps/libipnet-8e33934d86be4d6e.rlib" "/playground/target/debug/deps/libtokio_native_tls-095fa4f445b9ada7.rlib" "/playground/target/debug/deps/libserde_urlencoded-c61505e8efe59184.rlib" "/playground/target/debug/deps/libencoding_rs-6db646af6aed58d2.rlib" "/playground/target/debug/deps/libserde_json-aaaea4d5f17e7bfd.rlib" "/playground/target/debug/deps/libryu-8177541eadb28761.rlib" "/playground/target/debug/deps/libbase64-263cbd5a5e64ab1a.rlib" "/playground/target/debug/deps/libmime_guess-eb8a1cb9893e4e18.rlib" "/playground/target/debug/deps/libunicase-b4234293fa194e2e.rlib" "/playground/target/debug/deps/libmime-f1104dec2de465c5.rlib" "/playground/target/debug/deps/libnative_tls-7028e32d0e94add2.rlib" "/playground/target/debug/deps/libopenssl_probe-7372e2218175cb8d.rlib" "/playground/target/debug/deps/libopenssl-84d1cdf5218f0b74.rlib" "/playground/target/debug/deps/libopenssl_sys-2038d81ad68cd2ed.rlib" "/playground/target/debug/deps/libforeign_types-37adb5bae539fda7.rlib" "/playground/target/debug/deps/libforeign_types_shared-22f2940fb592036b.rlib" "/playground/target/debug/deps/libbitflags-23cf02f711efe05e.rlib" "/playground/target/debug/deps/libhyper-430dd2c2e9afb7dd.rlib" "/playground/target/debug/deps/libwant-de668461c77b0f6d.rlib" "/playground/target/debug/deps/libtry_lock-30c95cee42568441.rlib" "/playground/target/debug/deps/libhttparse-ebba17a8d7f5b2dd.rlib" "/playground/target/debug/deps/libsocket2-abd46160d6c6c84a.rlib" "/playground/target/debug/deps/libh2-67e8c1f896ffcf25.rlib" "/playground/target/debug/deps/libtracing_futures-bfe252ef9bfa1357.rlib" "/playground/target/debug/deps/libindexmap-e59d655bbe32a039.rlib" "/playground/target/debug/deps/libhashbrown-89e2fd5a7081dfb3.rlib" "/playground/target/debug/deps/libahash-842a5b5404407a6a.rlib" "/playground/target/debug/deps/libconst_random-2c7202c77a6d1341.rlib" "/playground/target/debug/deps/libtokio_util-c597572dfab0a5a3.rlib" "/playground/target/debug/deps/libtower_service-25325533e6471f27.rlib" "/playground/target/debug/deps/libpin_project-85290df7927f46fd.rlib" "/playground/target/debug/deps/libhttpdate-7c9ae15df7de953a.rlib" "/playground/target/debug/deps/libtracing-1e9a893c023cc151.rlib" "/playground/target/debug/deps/libtracing_core-f4d747dfd45a5b1b.rlib" "/playground/target/debug/deps/libtokio-6caecbf8c961c6fc.rlib" "/playground/target/debug/deps/libsignal_hook_registry-464320536f92cd1a.rlib" "/playground/target/debug/deps/libnum_cpus-fa9405d418802dba.rlib" "/playground/target/debug/deps/libmio-8208b1b97ee75dd0.rlib" "/playground/target/debug/deps/libparking_lot-c70fd5290b63ba21.rlib" "/playground/target/debug/deps/libparking_lot_core-bec2d0cef1e036dd.rlib" "/playground/target/debug/deps/libsmallvec-be204749242d57d5.rlib" "/playground/target/debug/deps/liblock_api-9b94798a31b72387.rlib" "/playground/target/debug/deps/libscopeguard-9a7fcdcc3ef0c67a.rlib" "/playground/target/debug/deps/libinstant-801a426885a9fdfa.rlib" "/playground/target/debug/deps/libhttp_body-fa23070edd81973e.rlib" "/playground/target/debug/deps/libfutures_util-b297dd64f98a2e4a.rlib" "/playground/target/debug/deps/libmemchr-49ffcb39de512148.rlib" "/playground/target/debug/deps/libtokio_io-15767d74b5cad8b6.rlib" "/playground/target/debug/deps/libbytes-98612ff3704441d9.rlib" "/playground/target/debug/deps/libiovec-059f69bab14804ea.rlib" "/playground/target/debug/deps/liblibc-0a0510b4037c39f2.rlib" "/playground/target/debug/deps/libbyteorder-630514d63ec14067.rlib" "/playground/target/debug/deps/liblog-1181c8ecdf8fff43.rlib" "/playground/target/debug/deps/libcfg_if-ef24fecc97daf057.rlib" "/playground/target/debug/deps/libfutures-341be2426ac8006a.rlib" "/playground/target/debug/deps/libfutures_io-f642e5411fe1b621.rlib" "/playground/target/debug/deps/libslab-fae38ccb0866d90f.rlib" "/playground/target/debug/deps/libfutures_channel-ca57d40e72b73391.rlib" "/playground/target/debug/deps/libpin_project_lite-3a1c1edfcac5da66.rlib" "/playground/target/debug/deps/libfutures_sink-1e577cd08304b39b.rlib" "/playground/target/debug/deps/libfutures_task-285aea8d738140d9.rlib" "/playground/target/debug/deps/libonce_cell-49c2029294b89ee5.rlib" "/playground/target/debug/deps/libpin_utils-9d73d18d1a913b9e.rlib" "/playground/target/debug/deps/libfutures_core-3c03d3ccebe39c3b.rlib" "/playground/target/debug/deps/liblazy_static-a2d7352f0b2d8328.rlib" "/playground/target/debug/deps/liburl-3738c4378d8afb19.rlib" "/playground/target/debug/deps/libidna-44ceb179b4e434c3.rlib" "/playground/target/debug/deps/libunicode_normalization-7b85e62e0830fcdd.rlib" "/playground/target/debug/deps/libtinyvec-0fd102c28a026123.rlib" "/playground/target/debug/deps/libtinyvec_macros-373a732416c546b7.rlib" "/playground/target/debug/deps/libserde-f598327513f0f87c.rlib" "/playground/target/debug/deps/libunicode_bidi-a18e706d77b75aca.rlib" "/playground/target/debug/deps/libform_urlencoded-4539bb7bd3b31a2c.rlib" "/playground/target/debug/deps/libpercent_encoding-6c71419d296d9169.rlib" "/playground/target/debug/deps/libmatches-396398bf8ad55ae0.rlib" "/playground/target/debug/deps/libhttp-bc59be26651c0476.rlib" "/playground/target/debug/deps/libitoa-97b61b74c453bfb8.rlib" "/playground/target/debug/deps/libbytes-196811ca1432aaea.rlib" "/playground/target/debug/deps/libfnv-f0ba3a8dcbb1e827.rlib" "-Wl,--start-group" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-6f77337c1826707d.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e238540f8faf9927.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-78f8506dd5004913.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-c0e64497deb085aa.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-217a514dc8d845c6.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-65e4f8df4b8bbd73.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-fec1b74170245419.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e74f867eb2f15322.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-72a374d36f3d0a31.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-cb9206ed96de54c3.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-33ee81149d314805.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-2e8740599b11634b.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-241cf59851357bea.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-edc29aa8c04b480f.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-6a141406945fda5a.rlib" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-2408224b4af46d83.rlib" "-Wl,--end-group" "/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d36087076e1dd756.rlib" "-Wl,-Bdynamic" "-lssl" "-lcrypto" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc"
  = note: collect2: fatal error: ld terminated with signal 9 [Killed]
          compilation terminated.
          

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.

另一方面,当我在本地机器 (Windows 10)上尝试相同的代码时,它会编译,但会引发以下错误:
D:\DANI\rust\projects\httpget>cargo run    Compiling httpget v0.1.0 (D:\DANI\rust\projects\httpget)
    Finished dev [unoptimized + debuginfo] target(s) in 2.80s
     Running `target\debug\httpget.exe` Request: https://httpbin.org/ip thread 'main' panicked at 'not currently running on a Tokio 0.2.x runtime.', C:\Users\dani\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.25\src\runtime\handle.rs:118:28 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace         error: process didn't exit successfully: `target\debug\httpget.exe` (exit code: 101)
我检查了Cargo.toml中的依赖项:
[dependencies]
error-chain = "0.12.4"
reqwest = { version = "0.10" }
tokio = { version = "1", features = ["full"] }
futures = "0.3"
我认为它与async/await运行时有关,但是我是Rust语言的新手,我在网络上发现的有关此问题的信息对我来说还不清楚。
如果有人可以帮助解决这些问题,我将不胜感激!
提前致谢!
丹妮·P。

最佳答案

这是reqwest版本的问题。将您的原始版本替换为

reqwest = { version = "0.11" }
在Cargo.toml中应将其修复在本地计算机上。

关于rust - Rust Playground和本地计算机中reqwest示例的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66409193/

相关文章:

rust - 在枚举定义的列表数据结构上插入方法

rust - 如何通过 libc::getgroups 为用户获取组?

javascript - 不明白如何在异步函数中返回函数数组的答案

rust - 如何在不使用 Tokio 同时运行相同功能的情况下以重复间隔同时运行一组功能?

rust - 为什么即使在未来解决之后,在循环中使用带有 Tokio future 的克隆 super 客户端也会阻塞?

rust - 变异和非变异方法链

rust - 我可以在不使用泛型类型的情况下获得多特征实例的特征对象吗?

javascript - Nodejs 从嵌套函数返回结果

javascript - 在 Javascript 中共享异步函数响应的简洁方法是什么?

http - 如何在 Rust 中使用 hyper、tokio 和 futures 为 HTTP 请求设置超时?