我想你会做这样的事情:
extern crate uuid;
use uuid::Uuid;
use std::fmt::Formatter;
use std::fmt::Debug;
#[derive(Debug)]
struct BlahLF {
id: Uuid,
}
impl BlahLF {
fn new() -> BlahLF {
return BlahLF { id: Uuid::new_v4() };
}
}
impl Debug for BlahLF {
fn fmt(&self, &mut f: Formatter) -> Result {
write!(f.buf, "Hi: {}", self.id);
}
}
...但是尝试实现这个特性会产生:
error[E0243]: wrong number of type arguments
--> src/main.rs:19:41
|
19 | fn fmt(&self, &mut f: Formatter) -> Result {
| ^^^^^^ expected 2 type arguments, found 0
然而,其他实现似乎就是这样做的。我究竟做错了什么?
根据来自的例子std::fmt docs http://static.rust-lang.org/doc/master/std/fmt/index.html:
extern crate uuid;
use uuid::Uuid;
use std::fmt;
struct BlahLF {
id: Uuid,
}
impl fmt::Debug for BlahLF {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Hi: {}", self.id)
}
}
需要强调的部分是fmt::
in fmt::Result
。如果没有它,你指的是普通的Result http://static.rust-lang.org/doc/master/std/result/enum.Result.html类型。平原Result
type does有两个泛型类型参数,fmt::Result
没有。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)