相关疑难解决方法(0)

派生特征会导致意外的编译器错误,但手动实现会起作用

这段代码(游乐场):

#[derive(Clone)]
struct Foo<'a, T: 'a> {
    t: &'a T,
}

fn bar<'a, T>(foo: Foo<'a, T>) {
    foo.clone();
}
Run Code Online (Sandbox Code Playgroud)

......不编译:

error: no method named `clone` found for type `Foo<'a, T>` in the current scope
  --> <anon>:7:9
   |>
16 |>     foo.clone();
   |>         ^^^^^
note: the method `clone` exists but the following trait bounds were not satisfied: `T : std::clone::Clone`
help: items from traits can only be used if the trait is implemented and in scope; the following trait defines …
Run Code Online (Sandbox Code Playgroud)

clone rust

14
推荐指数
1
解决办法
1226
查看次数

标签 统计

clone ×1

rust ×1