我正在使用 [prost] 从 protobuf 生成结构。其中一个结构非常简单:
enum Direction {
up = 0;
down = 1;
sideways = 2;
}
Run Code Online (Sandbox Code Playgroud)
这会生成如下代码:
enum Direction {
up = 0;
down = 1;
sideways = 2;
}
Run Code Online (Sandbox Code Playgroud)
我必须将大量 JSON 文件解析为这些消息。这些有数万行长,但是当这个字段出现时,它看起来像:
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
#[derive(serde_derive::Deserialize)]
pub enum Direction {
Up = 0,
Down = 1,
Sideways = 2,
}
Run Code Online (Sandbox Code Playgroud)
所以,简而言之,它的反序列化格式是字符串,序列化后是i32。
如果我只是运行它,并尝试解析 JSON,我会得到:
thread 'tests::parse_json' panicked at 'Failed to parse: "data/my_data.json": Error("invalid type: string \"up\", expected i32", line: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 crates prost 和 tonic 在 Rust 中构建一个简单的 gRPC 客户端。我的 proto 定义非常简单,但我突然坚持使用从其他 proto 导入的消息。
// file src/protos/types.proto
syntax = "proto3";
package Types;
message Message1 {
uint32 value1 = 1;
bytes value2 = 2;
}
message Message2 {
uint32 value1 = 1;
uint32 value2 = 2;
uint32 value3 = 3;
uint32 value4 = 4;
}
Run Code Online (Sandbox Code Playgroud)
// file src/protos/service.proto
syntax = "proto3";
import "types.proto";
package Service;
service Worker {
rpc Do (Request) returns (Reply);
}
message Request {
Types.Message1 message1 = 1; …Run Code Online (Sandbox Code Playgroud) 如何将数据传递到toniconeof中的protobuf ?
我在文档中找不到任何说明或示例。
我正在使用 prost 为 protobuf 生成 Rust 类。我希望 Clippy 忽略这些生成的文件,但我无法弄清楚如何让 Clippy 忽略它们。
在我的 lib.rs 文件中,我有
pub mod modes {
#[allow(clippy)]
include!(concat!(env!("OUT_DIR"), "/modes.rs"));
}
#[allow(clippy)]
pub mod vehicle_features {
include!(concat!(env!("OUT_DIR"), "/vehicle_features.rs"));
}
Run Code Online (Sandbox Code Playgroud)
但是,我仍然收到 models.rs 和vehicle_features.rs 文件的警告。如何在不修改文件的情况下忽略clippy中的这些模块/文件。
编辑:根据以下建议,我将代码更改为:
pub mod modes {
#![allow(clippy::all)]
include!(concat!(env!("OUT_DIR"), "/modes.rs"));
}
pub mod vehicle_features {
#![allow(clippy::all)]
include!(concat!(env!("OUT_DIR"), "/vehicle_features.rs"));
}
Run Code Online (Sandbox Code Playgroud)
这在跑步时有效cargo clippy,但在跑步时不起作用cargo clippy -- -W unwrap_used有人知道为什么吗?当我向 Clippy 添加额外的警告参数时,如何使其工作?
编辑2:
我在这里找到了答案:How to disable a Clippy lint for a single line / block?
“clippy:all 实际上并不允许所有 lints,而是允许正确性、可疑性、风格、复杂性、cargo …