rust - Trying to implement core::fmt::Show -
i trying implement core::fmt::show binary tree. implement code :
impl<t: partialeq + partialord + show> show 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 compiler throw following error :
compiling binary_tree v0.0.1 (file:///home/guillaume/projects/binary_tree) src/binary_tree.rs:60:2: 77:3 error: method
fmt
has incompatible type 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. complete code found here. comments code welcome.
the error telling method fmt
not have type expects, , in particular found &-ptr (i.e., &str) there should formaterror.
changing method signature fix compilation error:
fn fmt(&self, f: &mut formatter) -> result<(), fmt::formaterror>
i have sent pull request on github makes change (and fixes test verify work)
Comments
Post a Comment