Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Rust is planning to add that eventually, but in the meantime:

    fn foo(n: i32) -> i32 {
        n * 2
    }
    const y: i32 = foo(3);
error: function calls in constants are limited to struct and enum constructors [E0015]


You can do it with a compiler plugin; I suspect that's what the parent comment was referring to. Admittedly compiler plugins are pretty experimental at this time.


Sorry about that. I haven't tried this myself, I was told by a Rust user that its CTFE was on par with D's. I guess he was mistaken.


Not even close, sadly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: