derive_more
derive_more copied to clipboard
Constructor generated new should be marked const
For example, given this struct:
#[derive(Constructor)]
struct Foo { x: f32, y: f32 }
The generated code should be:
impl Foo {
const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
}
As far as I know this should be fine to do on the current stable. It's an easy change, would a PR adding this be accepted?
A pull request would be accepted for this assuming it doesn't break Rust 1.36.0 (which is the currently lowest supported Rust). To do so you might have to check the version with rustc_version in the build.rs script.
Unfortunately const fn is not quite as stable as I thought, for example trait bounds aren't yet supported in stable (https://github.com/rust-lang/rfcs/pull/2632). I think this issue will have to wait until const fn is more mature.
Any plans for this? Having const constructors would be a nice feature.
One option for how it could be rendered is if we add #[CosntConstructor] to the derive macros. Then if the const-ness is not supported you have alternatives. No need for complex logic, just a conscious choice.