Closed
Description
I tried this code:
fn main() {
let mut log_service = LogService { inner: Inner };
log_service.call(());
}
pub trait Service<Request> {
type Response;
fn call(&mut self, req: Request) -> Self::Response;
}
pub struct LogService<S> {
inner: S,
}
impl<T, U, S> Service<T> for LogService<S>
where
S: Service<T, Response = U>,
U: Extension + 'static,
for<'a> U::Item<'a>: std::fmt::Debug,
{
type Response = S::Response;
fn call(&mut self, req: T) -> Self::Response {
self.inner.call(req)
}
}
pub struct Inner;
impl Service<()> for Inner {
type Response = Resp;
fn call(&mut self, req: ()) -> Self::Response {
Resp::A(req)
}
}
pub trait Extension {
type Item<'a>;
fn touch<F>(self, f: F) -> Self
where
for<'a> F: Fn(Self::Item<'a>);
}
pub enum Resp {
A(()),
}
impl Extension for Resp {
type Item<'a> = RespItem<'a>;
fn touch<F>(self, _f: F) -> Self
where
for<'a> F: Fn(Self::Item<'a>),
{
match self {
Self::A(a) => Self::A(a),
}
}
}
pub enum RespItem<'a> {
A(&'a ()),
}
impl<'a> std::fmt::Debug for RespItem<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::A(arg0) => f.debug_tuple("A").field(arg0).finish(),
}
}
}
Meta
rustc --version --verbose
:
rustc 1.66.0-nightly (bed4ad65b 2022-10-25)
binary: rustc
commit-hash: bed4ad65bf7a1cef39e3d66b3670189581b3b073
commit-date: 2022-10-25
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
Backtrace
error[E0599]: the method `call` exists for struct `LogService<Inner>`, but its trait bounds were not satisfied
--> src/main.rs:3:17
|
3 | log_service.call(());
| ^^^^ method cannot be called on `LogService<Inner>` due to unsatisfied trait bounds
...
12 | pub struct LogService<S> {
| ------------------------
| |
| method `call` not found for this struct
| doesn't satisfy `LogService<Inner>: Service<_>`
|
note: trait bound `<_ as Extension>::Item<'a>: Debug` was not satisfied
--> src/main.rs:20:26
|
16 | impl<T, U, S> Service<T> for LogService<S>
| ---------- -------------
...
20 | for<'a> U::Item<'a>: std::fmt::Debug,
| ^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
For more information about this error, try `rustc --explain E0599`.