相关疑难解决方法(0)

如何实现自定义'fmt :: Debug'特性?

我猜你做的事情是这样的:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

...但是尝试实现此特征会产生:

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 …
Run Code Online (Sandbox Code Playgroud)

rust

42
推荐指数
1
解决办法
1万
查看次数

标签 统计

rust ×1