Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The trait Message is not implemented #1858

Open
kurudj opened this issue Aug 6, 2024 · 4 comments
Open

The trait Message is not implemented #1858

kurudj opened this issue Aug 6, 2024 · 4 comments

Comments

@kurudj
Copy link

kurudj commented Aug 6, 2024

Bug Report

Version

│ │ └── tonic v0.12.1
│ │ └── tonic-build v0.12.1
│ ├── tonic v0.12.1 (*)

Platform

6.1.82-99.168.amzn2023.x86_64

Description

Upon generating Rust files from proto files as well as a service, the service build yields an issue with Message trait not being implemented for a struct generated from a proto message, despite the Rust file explicitly having a ::prost::Message derive.

I tried this code:

tonic_build::configure()
        .build_server(true)
        .out_dir("src")
        .type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
        .compile(&["MyStruct.proto"], &["src/raw/structs"])?;*/

tonic_build::configure().build_server(true).out_dir("src").compile(&["MyStructService.proto"], &["src/raw/structs"])?;

Where the Cargo.toml is:

[dependencies]
tonic = "0.12"
prost = "0.13"
serde = { version = "1.0", features = ["derive"] }

[build-dependencies]
tonic-build = "0.12"

This yields a MyStruct.rs with my main message as a struct:

#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MyStruct {

Within the service the following code throws the following errors:

error[E0277]: the trait bound `MyStruct: Message` is not satisfied
    |
242 |                         let mut grpc = tonic::server::Grpc::new(codec)
    |                                        ------------------------ ^^^^^ the trait `Message` is not implemented for `MyStruct`, which is required by `ProstCodec<_, _>: Codec`
    |                                        |
    |                                        required by a bound introduced by this call
@kurudj kurudj closed this as completed Aug 6, 2024
@kurudj kurudj reopened this Aug 6, 2024
@Frank-Krick
Copy link

I had a similar issue, with 170 or so build errors related to prost::Message and other traits. What solved it for me was adding prost to the project dependencies.
Looks like a similar thing to me, so maybe that'll help.

@dmitrygrigoryev
Copy link

Have the same problem in my project. Maybe somebody can share an any workaround to fix this problem?

@Frank-Krick
Copy link

Does adding prost to your dependencies help? cargo add prost

@dmitrygrigoryev
Copy link

dmitrygrigoryev commented Oct 3, 2024

Combination of tonic 0.9.2 and prost/prost-types 0.11.9 works! I think there were a mess between dependencies, cause one of my dependencies locks the tonic version to 0.9.2. It is just proposal.

My Cargo.toml with newest versions of dependencies was:

[dependencies]
prost = "0.13.3"
prost-types = "0.13.3"
dependency_with_tonic0.9.2 = { path = "../../libraries/dependency_with_tonic0.9.2", default-features = false}
tonic = "0.12.3"

So, yes I've tried to add prost to dependencies, in my case it did not help(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants