【发布时间】:2020-07-21 11:40:49
【问题描述】:
#[derive(Debug)]
struct Point {
x: i32,
y: i32,
}
impl Copy for Point {}
impl Clone for Point {
fn clone(&self) -> Point {
*self
}
}
当我只实现 Copy 时,Rust 告诉我需要实现 Clone。当我只实现Clone 时,Rust 告诉我Point 可以移动。
我的问题是,我从来没有实现过任何东西,这段代码有点像循环依赖,但它有效吗?为什么?
【问题讨论】:
-
它不是循环依赖,但确实可能有点令人惊讶。考虑启用this Clippy lint。
-
Rust 永远不会自动克隆。
标签: rust