gpt4 book ai didi

rust - 为什么 match 不起作用而 PartialEq/Eq 工作正常?

转载 作者:行者123 更新时间:2023-11-29 08:22:25 27 4
gpt4 key购买 nike

<分区>

我有这个简单的代码:

#[derive(Copy, Clone, Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
struct NodeIndex(u32);

fn main() {
let i = NodeIndex(5323);
let from = NodeIndex(21030);
let to = NodeIndex(21031);

println!("from == i => {}, to == i => {}", from == i, to == i);

match i {
from => println!("1"),
to => println!("2"),
_ => println!("other"),
}
}

它打印:

from == i => false, to == i => false
1

所以 i != fromi != to,但是 match 调用 from => println!("1"),,这是怎么回事?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com