Skip to content

Instantly share code, notes, and snippets.

@mcr
Created November 13, 2020 23:18
Show Gist options
  • Save mcr/fecf6cd83104e395d56f2c38d5a30cc0 to your computer and use it in GitHub Desktop.
Save mcr/fecf6cd83104e395d56f2c38d5a30cc0 to your computer and use it in GitHub Desktop.
pub fn setup_writer(writer: tokio::net::UnixStream) -> impl Stream {
let my_write_stream = FramedWrite::new(writer, LengthDelimitedCodec::new());
return tokio_serde::SymmetricallyFramed::new(my_write_stream, SymmetricalCbor::default());
}
let mut serialized = setup_writer(pair.0);
...
to refactor from code that did:
let writer = pair.0;
let my_write_stream = FramedWrite::new(writer, LengthDelimitedCodec::new());
let mut serialized = tokio_serde::SymmetricallyFramed::new(my_write_stream, SymmetricalCbor::default());
@mcr
Copy link
Author

mcr commented Nov 13, 2020

-*- mode: compilation; default-directory: "/ssw/projects/pandora/connect/connect/src/" -*-
Compilation started at Fri Nov 13 18:32:43

cargo test 
   Compiling connect v1.0.0 (/ssw/projects/pandora/connect/connect)
error[E0599]: no method named `send` found for struct `tokio_serde::Framed<tokio_util::codec::FramedWrite<dull::tokio::net::UnixStream, tokio_util::codec::LengthDelimitedCodec>, bytes::Bytes, bytes::Bytes, tokio_serde::formats::Cbor<bytes::Bytes, bytes::Bytes>>` in the current scope
   --> src/control.rs:89:16
    |
89  |     serialized.send(&data).await.unwrap();
    |                ^^^^ method not found in `tokio_serde::Framed<tokio_util::codec::FramedWrite<dull::tokio::net::UnixStream, tokio_util::codec::LengthDelimitedCodec>, bytes::Bytes, bytes::Bytes, tokio_serde::formats::Cbor<bytes::Bytes, bytes::Bytes>>`
    | 
   ::: /home/mcr/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-serde-0.7.1/src/lib.rs:215:1
    |
215 | pub struct Framed<Transport, Item, SinkItem, Codec> {
    | ---------------------------------------------------
    | |
    | doesn't satisfy `_: futures::Sink<_>`
    | doesn't satisfy `_: futures::SinkExt<_>`
    |
    = note: the method `send` exists but the following trait bounds were not satisfied:
            `tokio_serde::Framed<tokio_util::codec::FramedWrite<dull::tokio::net::UnixStream, tokio_util::codec::LengthDelimitedCodec>, bytes::Bytes, bytes::Bytes, tokio_serde::formats::Cbor<bytes::Bytes, bytes::Bytes>>: futures::Sink<_>`
            which is required by `tokio_serde::Framed<tokio_util::codec::FramedWrite<dull::tokio::net::UnixStream, tokio_util::codec::LengthDelimitedCodec>, bytes::Bytes, bytes::Bytes, tokio_serde::formats::Cbor<bytes::Bytes, bytes::Bytes>>: futures::SinkExt<_>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `connect`.

To learn more, run the command again with --verbose.

Compilation exited abnormally with code 101 at Fri Nov 13 18:32:45

@mcr
Copy link
Author

mcr commented Nov 13, 2020

-*- mode: compilation; default-directory: "/ssw/projects/pandora/connect/connect/src/" -*-
Compilation started at Fri Nov 13 18:37:43

cargo test 
   Compiling connect v1.0.0 (/ssw/projects/pandora/connect/connect)
error[E0277]: the trait bound `bytes::Bytes: control::serde::Serialize` is not satisfied
  --> src/control.rs:53:56
   |
53 | pub fn setup_writer(writer: tokio::net::UnixStream) -> impl Sink<Bytes> {
   |                                                        ^^^^^^^^^^^^^^^^ the trait `control::serde::Serialize` is not implemented for `bytes::Bytes`
...
56 |     return tokio_serde::SymmetricallyFramed::new(my_write_stream, SymmetricalCbor::default());
   |            ---------------------------------------------------------------------------------- this returned value is of type `tokio_serde::Framed<tokio_util::codec::FramedWrite<dull::tokio::net::UnixStream, tokio_util::codec::LengthDelimitedCodec>, bytes::Bytes, bytes::Bytes, tokio_serde::formats::Cbor<bytes::Bytes, bytes::Bytes>>`
   |
   = note: required because of the requirements on the impl of `tokio_serde::Serializer<bytes::Bytes>` for `tokio_serde::formats::Cbor<bytes::Bytes, bytes::Bytes>`
   = note: required because of the requirements on the impl of `futures::Sink<bytes::Bytes>` for `tokio_serde::Framed<tokio_util::codec::FramedWrite<dull::tokio::net::UnixStream, tokio_util::codec::LengthDelimitedCodec>, bytes::Bytes, bytes::Bytes, tokio_serde::formats::Cbor<bytes::Bytes, bytes::Bytes>>`
   = note: the return type of a function must have a statically known size

error[E0308]: mismatched types
  --> src/control.rs:90:21
   |
90 |     serialized.send(&data).await.unwrap();
   |                     ^^^^^ expected struct `bytes::Bytes`, found `&&control::DullControl`

error[E0599]: no method named `unwrap` found for enum `std::result::Result<(), <impl futures::Sink<bytes::Bytes> as futures::Sink<bytes::Bytes>>::Error>` in the current scope
  --> src/control.rs:90:34
   |
90 |     serialized.send(&data).await.unwrap();
   |                                  ^^^^^^ method not found in `std::result::Result<(), <impl futures::Sink<bytes::Bytes> as futures::Sink<bytes::Bytes>>::Error>`
   |
   = note: the method `unwrap` exists but the following trait bounds were not satisfied:
           `<impl futures::Sink<bytes::Bytes> as futures::Sink<bytes::Bytes>>::Error: std::fmt::Debug`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0308, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `connect`.

To learn more, run the command again with --verbose.

Compilation exited abnormally with code 101 at Fri Nov 13 18:37:45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment