我想定义Ord一个自定义类型,以便根据到Advent of Code 2019 day 10 的Point原点的距离进行排序:
impl std::cmp::Ord for Point {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
let this = self.x * self.x + self.y + self.y;
let that = other.x * other.x + other.y * other.y;
return this.cmp(&that);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我遇到了这个编译错误:
= 帮助:该特征
std::cmp::PartialOrd尚未实现helpers::models::Point
的文档PartialOrd仅解释如何导出或实现它。这些都很清楚。
为什么Ord取决于这个?Partial特征名称中的名称意味着什么?什么时候会用到呢?
| 归档时间: |
|
| 查看次数: |
8223 次 |
| 最近记录: |