Actix: returning protobuf - Message not implemented

I am using actix-web, actix-protobuf and prost-build in a web application.

I have a .proto file defined and I use proto-build to generate corresponding structs, which look similar to the following.

#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Item {
    #[prost(string, tag="1")]
    pub a: ::prost::alloc::string::String,
    // ...

#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Items {
    #[prost(message, repeated, tag="1")]
    pub items: ::prost::alloc::vec::Vec<Item>,

Now, in web application I'm trying to use actix-protobuf in order to return data as follows.

let data: Items = ...
return HttpResponse::Ok().protobuf(data);

At this point I'm getting an error

the trait `prost::message::Message` is not implemented for `Items`

In the protobuf example (Actix examples - protobuf), they're using Message from prost-derive crate..
(So it looks like there's prost::Message as well as prost::message::Message. )

Any advice would be appreciated.

What do you have in the [dependencies] section of your Cargo.toml? Sometimes confusing errors like this arise when you inadvertently depend on two incompatible versions of the same crate.

1 Like

Interesting point. This is what I have in Cargo.toml.

actix-protobuf = "0.7.0-beta.4"
actix-web = "4.0.0-rc.2"
bytes = "1.1.0"
prost = "0.9.0"

prost-build = "0.9.0"

I solved the problem but changing the dependency in Cargo.toml from prost = "0.9.0" to the following:

prost = {version = "0.8.0", default_features = false, features = ["prost-derive"] }

However, the above is using an older version or prost.
The following does NOT work.

prost = {version = "0.9.0", default_features = false, features = ["prost-derive"] }

Right, because the version of actix-protobuf you're using depends on prost ^0.8.0, so if you don't specify a version that's compatible with that (as 0.9.0 is not) then you will get both versions.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.