Skip to content

Compile time optimization #62

@mlund

Description

@mlund

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions