Skip to content

Instantly share code, notes, and snippets.

@feymartynov
Created September 9, 2019 09:33
Show Gist options
  • Save feymartynov/41fb2299c9dbce79227152210b9a4ade to your computer and use it in GitHub Desktop.
Save feymartynov/41fb2299c9dbce79227152210b9a4ade to your computer and use it in GitHub Desktop.
OutgoingMessage -> dyn Publishable cast problem
$ cargo build
Compiling wtf v0.1.0 (/Users/fey/wtf)
error[E0271]: type mismatch resolving `<impl core::future::future::Future as core::future::future::Future>::Output == std::result::Result<std::vec::Vec<std::boxed::Box<(dyn svc_agent::mqtt::Publishable + 'static)>>, std::string::String>`
--> src/main.rs:11:22
|
11 | async fn create() -> Result<Vec<Box<dyn Publishable>>, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `svc_agent::mqtt::OutgoingMessage`, found trait svc_agent::mqtt::Publishable
|
= note: expected type `std::result::Result<std::vec::Vec<std::boxed::Box<svc_agent::mqtt::OutgoingMessage<Data, svc_agent::mqtt::OutgoingResponseProperties>>>, _>`
found type `std::result::Result<std::vec::Vec<std::boxed::Box<(dyn svc_agent::mqtt::Publishable + 'static)>>, std::string::String>`
= note: the return type of a function must have a statically known size
error: aborting due to previous error
For more information about this error, try `rustc --explain E0271`.
error: Could not compile `wtf`.
To learn more, run the command again with --verbose.
[package]
name = "wtf"
version = "0.1.0"
authors = []
edition = "2018"
[dependencies]
serde = "1.0"
serde_derive = "1.0"
[dependencies.futures]
version = "=0.3.0-alpha.18"
package = "futures-preview"
[dependencies.svc-agent]
git = "https://github.com/netology-group/svc-agent-rs"
branch = "feature/ULMS-577"
use futures::executor;
use serde_derive::Serialize;
use svc_agent::Destination;
use svc_agent::mqtt::{Publishable, OutgoingMessage, OutgoingResponseProperties, ResponseStatus};
#[derive(Debug, Serialize)]
struct Data {
foo: String,
}
async fn create() -> Result<Vec<Box<dyn Publishable>>, String> {
let message = OutgoingMessage {
payload: Data { foo: "bar".to_string() },
properties: OutgoingResponseProperties::new(ResponseStatus::OK, "whatever"),
destination: Destination::Broadcast("nevermind".to_string()),
};
Ok(vec![Box::new(message)])
}
async fn run() -> Result<(), String> {
let messages = create().await?;
for message in messages.iter() {
println!("{:?}", message.to_bytes());
}
Ok(())
}
fn main() {
executor::block_on(run()).expect("Error running an executor");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment