Skip to content

Global constants vs associated constants #3992

Answered by matklad
EgorKulikov asked this question in General
Discussion options

You must be logged in to vote

👍, with a caveat.

Caveat: Rust's primary units of encapsulation are a module and a crate, so generally it's perfectly fine to have stuff in module namespace. It is not a problem by itself. Often, the opposite is true -- people needlessly put stuff in impl blocks.

So, if there's a bunch of FOO_XXX constants and a Foo type, it makes sense to write Foo::XXX instead. If, of the other hand, there's no single type to which a constant clearly belongs, it's better to leave it at the module level.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by frol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants