Why does Rust support associating const but not static variables with struct?

Is it due to lifetime?

There was a draft proposal for associated statics a while ago, but I don't think anyone has been actively working on the design or implementation since then. I don't think there are fundamental obstacles; it may be more a matter of motivation and priority.

1 Like

You can approximate it with a function that returns a reference to a local static.

pub struct Foo;

impl Foo {
    pub fn bar() -> &'static [u8] {
        static BAR: [u8; 3] = [1, 2, 3];