In a library I'm writing to understand Rust I created a trait Decodeable.
pub trait Decodeable {
fn read_and_decode(&mut types::ReadSeeker) -> Result<Self, ::error::Error>;
}
I then implemented the type:
impl Decodeable for u32 {
fn read_and_decode(&mut stream: types::ReadSeeker) -> Result<u32, error::Error> {
try!(stream.big_edian_read_u32());
}
}
This was failing with an error of:
error: method `read_and_decode` has an incompatible type for trait:
expected &-ptr,
found trait types::ReadSeeker
I eventually figured out if I change the function signature to read_and_decode(stream: &mut types::ReadSeeker)
, it worked.
I'd like to understand what the difference between &mut stream: types::ReadSeeker
and stream: &mut types::ReadSeeker
. This feels like it is a fundamental part of rust, but I don't have any grasp on what the difference is beyond the fact that they are in fact different.