I am trying to implement the core::fmt::Show for my binary tree. This is my implement code :
impl<T: PartialEq + PartialOrd + Show> Show for Node<T>
{
fn fmt(&self, f: &mut Formatter) -> Result<(), &str>
{
match self.left {
Some(ref x) => {x.fmt(f);},
None => {}
};
match self.value {
Some(ref x) => {
write!(f, "{}", x.to_string().as_slice());
},
None => {}
};
match self.right {
Some(ref x) => {x.fmt(f);},
None => {}
};
Ok(())
}
}
But the compiler throw the following error :
Compiling binary_tree v0.0.1 (file:///home/guillaume/projects/binary_tree) src/binary_tree.rs:60:2: 77:3 error: method
fmthas an incompatible type for trait: expected enum core::fmt::FormatError, found &-ptr [E0053] src/binary_tree.rs:60 fn fmt(&self, f: &mut Formatter) -> Result<(), &str> src/binary_tree.rs:61 { src/binary_tree.rs:62 match self.left { src/binary_tree.rs:63 Some(ref x) => {x.fmt(f);}, src/binary_tree.rs:64 None => {} src/binary_tree.rs:65 };
I can't understand why. The complete code could be found here. Any comments about my code are welcome.