我正在尝试在传输中使用非默认tick()
方法编写流式传输流水线服务器。我认为这会做到这一点:
use std::io;
use mio::net::TcpListener;
use tokio_core::reactor::PollEvented;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_io::codec::{Framed, Encoder, Decoder};
use tokio_proto::streaming::pipeline::Transport;
use codec::PacketCodec;
type GearmanIO = PollEvented<TcpListener>;
type GearmanFramed = Framed<GearmanIO, PacketCodec>;
impl Transport for GearmanFramed {
fn tick(&mut self) {
trace!("tick!");
}
fn cancel(&mut self) -> io::Result<()> {
trace!("cancel!");
}
}
但是,尝试构建此文件会产生以下结果:
error[E0119]: conflicting implementations of trait `tokio_proto::streaming::pipeline::Transport` for type `tokio_io::codec::Framed<tokio_core::reactor::PollEvented<mio::net::TcpListener>, codec::PacketCodec>`:
--> src/transport.rs:14:1
|
14 | / impl Transport for GearmanFramed
15 | | {
16 | | fn tick(&mut self) {
17 | | trace!("tick!");
... |
22 | | }
23 | | }
| |_^
|
= note: conflicting implementation in crate `tokio_proto`
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> src/transport.rs:14:1
|
14 | / impl Transport for GearmanFramed
15 | | {
16 | | fn tick(&mut self) {
17 | | trace!("tick!");
... |
22 | | }
23 | | }
| |_^ impl doesn't use types inside crate
|
= note: the impl does not reference any types defined in this crate
= note: define and implement a trait or new type instead
我原以为由于“专业化”,它的具体性质GearmanFramed
将允许我实现该Transport
特征,但这仍然与默认值相冲突,此处为:
use tokio_io as new_io;
// ...
impl<T, C> Transport for new_io::codec::Framed<T,C>
where T: new_io::AsyncRead + new_io::AsyncWrite + 'static,
C: new_io::codec::Encoder<Error=io::Error> +
new_io::codec::Decoder<Error=io::Error> + 'static,
{}