小编pav*_*try的帖子

无法从另一个使用本地类型参数化的包中从另一个包中实现泛型类型的特征

这个测试代码(围栏):

use std::fmt::{Display, Formatter, Error};

struct MyLocalType;

type MyResult = Result<MyLocalType, String>;

impl Display for MyResult {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        f.write_str("some test string")
    }
}

fn main() { 
    let r: MyResult = Ok(MyLocalType); 
    println!("{}" , r); 
}
Run Code Online (Sandbox Code Playgroud)

生成此错误消息:

<anon>:7:1: 11:2 error: the impl does not reference any types defined in this crate; only traits defined in the current crate can be implemented for arbitrary types [E0117]
<anon>:7 impl Display for MyResult { …
Run Code Online (Sandbox Code Playgroud)

rust

5
推荐指数
1
解决办法
1441
查看次数

标签 统计

rust ×1