gpt4 book ai didi

rust - 访问没有范围限定符的关联常量项

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

我想在 impl R6502 中使用 const C 而不必指定作用域 R6502::

use bit::BitIndex;

pub struct R6502 {
pub sr: u8, // status register
}

impl R6502 {
// status flag indexs
const C: usize = 0;
const Z: usize = 1;

pub fn step(&mut self) {
self.sr.set_bit(R6502::C, false); // this is what I have to do
self.sr.set_bit(C, false); // this is what I want to do
}
}

我尝试使用 self::Cuse 的一些其他组合来仅获取有关未找到项目的错误。

最佳答案

使用相关常量在 Rust 1.20 中没有实现。我还没有找到与此相关的问题,因此您可以在 Rust GitHub 存储库中创建自己的问题。

同时,您可以使用类型别名来减少字符数。

type P = R6502;
self.sr.set_bit(P::C, false);

关于rust - 访问没有范围限定符的关联常量项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46230328/

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