gpt4 book ai didi

rust - 为什么是'futures::prelude::*;未声明

转载 作者:行者123 更新时间:2023-12-03 11:32:34 26 4
gpt4 key购买 nike

出于某种原因,它告诉我在我尝试遵循 rust 病IRC的示例时未声明它,并且没有用,这是没有意义的,因为我以前使用过这样的库,并且在此之前就可以使用了,所以idk是什么发生
代码:

use futures::prelude::*;
use irc::client::prelude::*;

#[tokio::main]
async fn main() -> irc::error::Result<()> {
let config = Config {
nickname: Some("pickles".to_owned()),
server: Some("chat.freenode.net".to_owned()),
channels: vec!["#rust-spam".to_owned()],
..Default::default()
};

let mut client = Client::from_config(config).await?;
client.identify()?;

let mut stream = client.stream()?;
let sender = client.sender();

while let Some(message) = stream.next().await.transpose()? {
print!("{}", message);

match message.command {
Command::PRIVMSG(ref target, ref msg) => {
if msg.contains(client.current_nickname()) {
sender.send_privmsg(target, "Hi!")?;
}
}
_ => (),
}
}

Ok(())
}
失误
 --> src\main.rs:1:5
|
1 | use futures::prelude::*;
| ^^^^^^^ use of undeclared type or module `futures`

error[E0308]: mismatched types
--> src\main.rs:9:19
|
9 | channels: vec!["#rust-spam".to_owned()],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected enum `std::option::Option`, found struct `std::vec::Vec`
| help: try using a variant of the expected enum: `Some(<[_]>::into_vec(box [$($x),+]))`
|
= note: expected enum `std::option::Option<std::vec::Vec<_>>`
found struct `std::vec::Vec<_>`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no function or associated item named `from_config` found for trait object `dyn irc::client::Client` in the current scope
--> src\main.rs:13:30
|
13 | let mut client = Client::from_config(config).await?;
| ^^^^^^^^^^^ function or associated item not found in `dyn irc::client::Client`

货代
[package]
name = "irc"
version = "0.1.0"
authors = ["sudo"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
irc = "0.13"
tokio = { version = "0.2.22", features = ["full"] }
编辑:添加了Cargo.toml

最佳答案

您将需要将 future crate 添加到您的 cargo 文件中。例如。从文档

[dependencies]
futures = "0.3"

关于rust - 为什么是'futures::prelude::*;未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64187536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com