getset icon indicating copy to clipboard operation
getset copied to clipboard

const getter

Open Luro02 opened this issue 6 years ago • 6 comments
trafficstars

Most, if not all getters (generic function parameters are currently unstable) can be const functions https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn

Luro02 avatar Sep 08 '19 11:09 Luro02

Great idea. :)

Hoverbear avatar Sep 19 '19 01:09 Hoverbear

Just checked in, this is still unstable. :(

Hoverbear avatar Nov 16 '19 19:11 Hoverbear

This is stable

const fn get_value(&self) -> &String {
    &self.value
}

Luro02 avatar Nov 17 '19 06:11 Luro02

Correct, but the generic case is not. :(

Hoverbear avatar Nov 18 '19 17:11 Hoverbear

Any updates to this? It doesn't seem reasonable to put this on hold just because of a special case. What about adding a feature gate or an attribute to enable const getters?

SOF3 avatar Jun 28 '21 03:06 SOF3

I was working on a rewrite of this lib to better support features like this, but it's not done yet.

You're welcome to contribute a patch to add this feature, or as always, write the getters and setters yourself (as is probably best!).

Hoverbear avatar Jun 29 '21 02:06 Hoverbear