如何使用筏板条箱和货物建造?

问题描述

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

但是不幸的是,当使用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板条箱的说明是:

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

看起来我似乎错过了protobuf周围的东西...但是什么?以及如何找到它?

解决方法

在发布版本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.lock中,并且您可以使用cargo update更新到较新的提交。