Created
September 9, 2019 09:33
-
-
Save feymartynov/41fb2299c9dbce79227152210b9a4ade to your computer and use it in GitHub Desktop.
OutgoingMessage -> dyn Publishable cast problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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