<分区>
在一个库中,我正在编写以了解 Rust,我创建了一个特征 Decodeable。
pub trait Decodeable {
fn read_and_decode(&mut types::ReadSeeker) -> Result<Self, ::error::Error>;
}
然后我实现了类型:
impl Decodeable for u32 {
fn read_and_decode(&mut stream: types::ReadSeeker) -> Result<u32, error::Error> {
try!(stream.big_edian_read_u32());
}
}
这是失败的错误:
error: method `read_and_decode` has an incompatible type for trait:
expected &-ptr,
found trait types::ReadSeeker
我最终发现,如果我将函数签名更改为 read_and_decode(stream: &mut types::ReadSeeker)
,它会奏效。
我想了解 &mut stream: types::ReadSeeker
和 stream: &mut types::ReadSeeker
之间的区别。这感觉像是使用rust 的一个基本部分,但除了它们实际上不同这一事实之外,我不知道有什么区别。