Are object-safe associated constants possible?

It is possible to make an associated function object safe by adding where Self: Sized bound. Is there a similar trick for associated constants?

Here's the playground which demonstrates the problem: Rust Playground

This appears to be a well-known limitation, perhaps temporary. There's some discussion of this in https://github.com/rust-lang/rust/issues/26847 and in this Reddit thread. The "workaround" (i.e. a pair of traits, one with an associated const and another without) is a real hack :slight_smile:.

2 Likes