I'm trying to use google pubsub but the example from the Publish section doesn't compile. Could somebody please shed some light on why, and how to fix it?
Thanks in advance
Link to the crate:
"doesn't compile" usually comes with an error message. It would be easier to help you if you share that, otherwise people will have to guess.
Sure, not a problem. Here is the error:
^ the trait
From<tonic::status::Status> is not implemented for
And, just to be clear, I know what that error means, but I don't understand why does it insists on the conversion. Apart from that, this is just code from the crates unmodified. It should just work.
When you post an error message, it's usually helpful to include the full error message as printed by
cargo build. Those are much larger than what you included here. It would be easier to help you if you share that, otherwise people will have to guess which line is triggering the error.
Sorry about that, my bad. This is the error msg:
error[E0277]: `?` couldn't convert the error to `google_cloud_gax::grpc::Status`
21 | topic.create(None, None).await?;
| ^ the trait `From<tonic::status::Status>` is not implemented for `google_cloud_gax::grpc::Status`
When you use the question mark operator, it will use the
From trait to automatically convert the error type into the one that the current function returns. You get that error if the error types cannot be converted.
If the examples in the README trigger that error, then you should file a bug to the library.
I took the liberty to edit your post to use a code block rather than a quote block for the error message, as they are much easier to read in a code block. Note also that error messages usually include some more information at the bottom, which you have not included here. I recommend including that next time.
Sure, I'll do that next time.
Would you perhaps know some workaround around that issue, until the library creators fix the issue?
You can use the
map_err method to manually convert the error.
topic.create(None, None).await.map_err(|tonic_err| convert_err(tonic_err))?;
Or you could change the error type returned by the function to something else, e.g.
Thank you. I'll try to do that.