Hello,
I am trying to play with the following code snipped (Rust Playground)
pub trait NodeRef : Copy + Sized {
type Error : error::Error;
}
#[derive(Debug)]
pub struct Error<NodeRefType> where NodeRefType : NodeRef {
kind : ErrorKind<NodeRefType>,
}
#[derive(Debug)]
enum ErrorKind<NodeRefType> where NodeRefType : NodeRef {
NodeRefError(<NodeRefType as NodeRef>::Error),
}
impl<NodeRefType> fmt::Display for Error<NodeRefType> where NodeRefType : NodeRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.kind {
ErrorKind::NodeRefError(ref err) => write!(f, "Referenced Node Error: {}", err),
}
}
}
impl<NodeRefType> error::Error for Error<NodeRefType> where NodeRefType : NodeRef {
fn description(&self) -> &str {
match self.kind {
ErrorKind::NodeRefError(ref err) => err.description(),
}
}
fn cause(&self) -> Option<&error::Error> {
match self.kind {
ErrorKind::NodeRefError(ref err) => Some(err),
}
}
}
And I get the following error:
31 | impl<NodeRefType> error::Error for Error<NodeRefType> where NodeRefType : NodeRef {
| ^^^^^^^^^^^^ the trait `std::fmt::Debug` is not implemented for `NodeRefType`
|
= help: consider adding a `where NodeRefType: std::fmt::Debug` bound
= note: required because of the requirements on the impl of `std::fmt::Debug` for `Error<NodeRefType>`
= note: required by `std::error::Error`
And the question is the following. I can not understand why does it want NodeRefType
following std::fmt::Debug
trait. NodeRefType
is not contained by Error
directly. Instead only NodeRefType::Error
is used (that is of Error
trait and follows Debug
trait).