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

trait prost::Message not implemented for Timestamp #1171

Open
duncanrhamill opened this issue Oct 4, 2024 · 1 comment
Open

trait prost::Message not implemented for Timestamp #1171

duncanrhamill opened this issue Oct 4, 2024 · 1 comment
Labels

Comments

@duncanrhamill
Copy link

Hello, I'm trying to use prost with a proto file that includes google.protobuf.Timestamp like so:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

message Command {
  google.protobuf.Timestamp timestamp = 1;
}

I'm using prost-build with the following build script:

prost_build::Config::new().compile_protos(
    &["../../proto/public.proto"],
    &["../../proto/"],
)?;

With these versions in my Cargo.toml:

[dependencies]
prost = { version = "0.13.3", features = ["prost-derive"] }
prost-types = "0.13.3"

[build-dependencies]
prost-build = "0.13.3"

However when I try to build I get the following error messages:

error[E0277]: the trait bound `Timestamp: prost::Message` is not satisfied
   --> <PROJECT_BUILD_PATH>/out/public.rs:7:28
    |
7   | #[derive(Clone, PartialEq, ::prost::Message)]
    |                            ^^^^^^^^^^^^^^^^ the trait `prost::Message` is not implemented for `Timestamp`
    |
    = help: the following other types implement trait `prost::Message`:
              bool
              i32
              i64
              u32
              u64
              f32
              f64
              public::Command
            and 7 others
note: required by a bound in `message::encode`
   --> <CARGO_PATH>\prost-0.13.3\src\encoding.rs:789:12
    |
787 |     pub fn encode<M>(tag: u32, msg: &M, buf: &mut impl BufMut)
    |            ------ required by a bound in this function
788 |     where
789 |         M: Message,
    |            ^^^^^^^ required by this bound in `encode`
    = note: this error originates in the derive macro `::prost::Message` (in Nightly builds, run with -Z 
macro-backtrace for more info)

This is with both rust 1.81 and 1.77.2, on Windows 10. I have tried using prost-wkt-types, setting the compile_well_known_types flag in the prost_build::Config, and setting various extern_path values to try and map the types correctly. What is frustrating is that I can see the #[derive(..., ::prost::Message)] on my instance of the Timestamp struct in the cargo registry!

Does anyone know how to fix this issue?

@duncanrhamill duncanrhamill changed the title trait prost::Message not implemented for Timestmp trait prost::Message not implemented for Timestamp Oct 4, 2024
younes-io added a commit to younes-io/prost that referenced this issue Oct 19, 2024
@caspermeijn
Copy link
Collaborator

The code you provide looks good to me. I do something similar and that works as expected. This feels to me that you are importing the wrong struct Timestamp. As you had already discovered prost_types::Timestamp already implements trait Message. https://docs.rs/prost-types/latest/prost_types/struct.Timestamp.html#impl-Message-for-Timestamp

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

Successfully merging a pull request may close this issue.

2 participants