首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >铁锈libp2p在板条箱libp2p中找不到函数development_transport

铁锈libp2p在板条箱libp2p中找不到函数development_transport
EN

Stack Overflow用户
提问于 2022-10-19 14:07:22
回答 1查看 105关注 0票数 0

我的代码一直在得到错误“在机箱'libp2p‘中找不到函数’。当我进入libp2p库(单击编辑器中的导入语句)时,它将显示libp2p文件(lib.rs)中的函数development_transport。有人知道为什么找不到这个函数吗?提前谢谢。

代码语言:javascript
复制
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)
            }
            _ => {}
        }
    }
}

我的Cargo.toml包含以下内容:

代码语言:javascript
复制
[dependencies]
libp2p = "0.49.0"
tokio = { version = "1.21.2", features = ["full"] }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-19 14:17:19

看看源代码,我看到了这个:

代码语言:javascript
复制
#[cfg(all(
    not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")),
    any(
        all(feature = "tcp-async-io", feature = "dns-async-std"),
        all(feature = "tcp", feature = "dns", feature = "async-std")
    ),
    feature = "websocket",
    feature = "noise",
    feature = "mplex",
    feature = "yamux"
))]
#[cfg_attr(
    docsrs,
    doc(cfg(all(
        not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")),
        any(
            all(feature = "tcp-async-io", feature = "dns-async-std"),
            all(feature = "tcp", feature = "dns", feature = "async-std")
        ),
        feature = "websocket",
        feature = "noise",
        feature = "mplex",
        feature = "yamux"
    )))
)]
#[cfg_attr(
    all(
        any(feature = "tcp-async-io", feature = "dns-async-std"),
        not(feature = "async-std")
    ),
    deprecated(
        since = "0.49.0",
        note = "The `tcp-async-io` and `dns-async-std` features are deprecated. Use the new `tcp` and `dns` features together with the `async-std` feature."
    )
)]
pub async fn development_transport(
    keypair: identity::Keypair,
) -> std::io::Result<core::transport::Boxed<(PeerId, core::muxing::StreamMuxerBox)>> {
...

因此,需要首先在Cargo.toml配置文件中启用某些特性。

正如你所看到的这里,他们说:

此版本有61个功能标志,其中0在默认情况下启用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74126811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档