我的代码总是得到错误“cannot find function development_transport in crate 'libp2p'。当我进入libp2p库时(单击编辑器中的import语句),它在libp2p的该文件(lib.rs)中显示函数development_transport。有人知道为什么找不到该函数吗?提前感谢。
use libp2p::futures::StreamExt;
use libp2p::swarm::dummy::Behaviour;
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::{identity, PeerId};
use std::error::Error;
# [tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id is: {}", local_peer_id);
let behaviour = Behaviour;
let transport = libp2p::development_transport(local_key)?;
let mut swarm = Swarm::new(transport, behaviour, local_peer_id);
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
loop {
match swarm.select_next_some().await {
SwarmEvent::NewListenAddr { address, .. } => {
println!("Listening on local address {:?}", address)
}
_ => {}
}
}
}
My Cargo.toml包含以下内容:
[dependencies]
libp2p = "0.49.0"
tokio = { version = "1.21.2", features = ["full"] }
1条答案
按热度按时间huus2vyu1#
查看source code,我看到以下内容:
因此,需要首先在
Cargo.toml
配置文件中启用某些特性。正如你所看到的here,他们说:
此版本有61个功能标志,默认情况下启用0个。