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

failed to use to_msg to convert Any to Message #921

Closed
c0mm4nd opened this issue Sep 17, 2023 · 5 comments
Closed

failed to use to_msg to convert Any to Message #921

c0mm4nd opened this issue Sep 17, 2023 · 5 comments

Comments

@c0mm4nd
Copy link

c0mm4nd commented Sep 17, 2023

Bug Report

Version

tonic 0.10.0 with prost 0.12.1

Platform

latest arch linux

Crates

tonic 0.10.0 with prost 0.12.1

Description

cannot convert Any to Message

the trait bound `my::Message: prost::name::Name` is not satisfied
the following other types implement trait `prost::name::Name`:
  prost_types::protobuf::Any
  prost_types::protobuf::Duration
  prost_types::protobuf::Timestamp
lib.rs(59, 22): required by a bound in `prost_types::<impl prost_types::protobuf::Any>::to_msg`

image

image

@LucioFranco
Copy link
Member

So this is as intended, for now only certain types have the implementation, but we need to implement #926 to fully take advantage of this.

@tarcieri
Copy link
Contributor

For now you can impl the Name trait by hand on my::Message

@c0mm4nd
Copy link
Author

c0mm4nd commented Oct 12, 2023

Thanks for your answers.
But I have one more question, is it possible to deserialize a known struct my::Message from any.value or just a Vec<u8>?

@tarcieri
Copy link
Contributor

@c0mm4nd you can use Any::to_msg with any message type which impls Name, which will also validate the type URL is correct for the message type

@tarcieri
Copy link
Contributor

Also this should probably be closed in favor of #926

@c0mm4nd c0mm4nd closed this as completed Oct 13, 2023
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