rkyv_codec icon indicating copy to clipboard operation
rkyv_codec copied to clipboard

Calling `SinkExt::flush` doesn't compile unless `Packet` is explicitly defined

Open jeromegn opened this issue 4 months ago • 1 comments

I am using feed to optimize flushing over the network. I'm getting compile errors if I don't specific the exact type I am flushing.

I understand why: it doesn't know what it's flushing because the sink accepts any kind of T that can be archived.

Seems like the trait bounds on the Sink implementation aren't enough. It needs a concrete type (I think).

Do you have a tip for handling this better on my end? I can use their long-form suggestion, but I'm feeding multiple types in there so I don't know which to choose (or if it even matters!). I assume things will break when I call feed if serialization fails. Flushing requiring Debug is cumbersome, haha!

error[E0283]: type annotations needed
   --> sprites-rs/src/proxy/mod.rs:299:36
    |
299 |             if let Err(e) = writer.flush().await {
    |                                    ^^^^^
    |
    = note: cannot satisfy `_: std::fmt::Debug`
    = note: required for `RkyvWriter<Compat<SendStream>, VarintLength>` to implement `futures::Sink<&_>`
note: required by a bound in `futures::SinkExt::flush`
   --> /Users/jerome/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/sink/mod.rs:65:26
    |
65  | pub trait SinkExt<Item>: Sink<Item> {
    |                          ^^^^^^^^^^ required by this bound in `SinkExt::flush`
...
207 |     fn flush(&mut self) -> Flush<'_, Self, Item>
    |        ----- required by a bound in this associated function
help: try using a fully qualified path to specify the expected types
    |
299 -             if let Err(e) = writer.flush().await {
299 +             if let Err(e) = <RkyvWriter<Compat<SendStream>, VarintLength> as SinkExt<&Packet>>::flush(&mut writer).await {
    |

jeromegn avatar Aug 26 '25 14:08 jeromegn