【问题标题】:How to use the raft-rs crate and build with cargo?如何使用 raft-rs 板条箱并使用货物进行构建?
【发布时间】:2020-08-22 03:25:54
【问题描述】:

我尝试构建single_mem_node example,但作为一个独立示例并将raft-rs crate 用作库。

但不幸的是,我在使用 cargo build 构建时遇到此构建错误

error[E0599]: no method named `is_empty` found for reference `&raft_proto::protos::eraftpb::Snapshot` in the current scope
   --> src/main.rs:123:26
    |
123 |     if !ready.snapshot().is_empty() {
    |                          ^^^^^^^^ method not found in `&raft_proto::protos::eraftpb::Snapshot`

我已经在 Cargo.toml 中声明了这些依赖项

[dependencies]
protobuf = { version = "2", features = ["with-bytes"] }
raft = "0.6.0-alpha"
slog = "2.5.2"
slog-term = "2.6.0"
slog-async = "2.5.0"

raft-rs crate 的使用说明如下:

您可以将 raft 与 rust-protobuf 或 Prost 一起使用来编码/解码 gRPC 消息。我们默认使用 rust-protobuf。要使用 Prost,请使用 prost-codec 功能构建(或依赖)Raft,而不使用默认功能。

看起来我确实想念protobuf 周围的一些东西...但是什么?以及如何得知?

【问题讨论】:

    标签: rust protocol-buffers rust-cargo


    【解决方案1】:

    看起来该方法是在发布0.6.0-alpha 版本之后添加的in this commit。 GitHub 默认显示master 分支,所以以后请尝试浏览与您正在使用的版本对应的提交。在这种情况下,它没有正确标记,但我认为this commit is the published 0.6.0-alpha version。在该提交的示例中,the corresponding line 是:

    if !raft::is_empty_snap(ready.snapshot()) {
    

    或者,由于 0.6.0-alpha 似乎是在 2019 年 7 月发布的,如果您想要对 master 的最新更改,您可以将 Cargo.toml 中的依赖关系更改为:

    raft = { git = "https://github.com/tikv/raft-rs" }
    

    在这种情况下,cargo 将获取最新的提交并将其哈希存储在 Cargo.lock 中,您可以使用 cargo update 更新到较新的提交。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-17
      • 2020-06-13
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 2020-07-24
      • 2017-10-13
      相关资源
      最近更新 更多