mos-hardware icon indicating copy to clipboard operation
mos-hardware copied to clipboard

Compile time optimization

Open mlund opened this issue 4 months ago • 1 comments

If updating to newer rust-mos, the current const traits are no longer supported. Compile time conversions and construction are available in nightly Rust, only. When available in stable, go over existing classes to minimize runtime computation. Ping @sbechet

// Tested with Nightly 1.91 (Aug. 2025)

#![feature(const_trait_impl)]
#![feature(const_from)]
#![feature(const_default)]
#![feature(derive_const)]

#[derive_const(Default)]
struct Byte(u8);

impl const From<u8> for Byte {
    fn from(a: u8) -> Self {
        Self(a)
    }
}

fn main() {
    const DEFAULT_BYTE: Byte = Byte::default();
    const BYTE: Byte = Byte::from(2);

    println!("{}", DEFAULT_BYTE.0);
    println!("{}", BYTE.0);
}

mlund avatar Aug 21 '25 13:08 mlund

Removed unstable rust, see #65

sbechet avatar Aug 21 '25 21:08 sbechet