Search code examples
rustnaming

Associated type (type parameter) naming convention


Rust's official naming guidelines suggest that we should use concise UpperCamelCase, usually single uppercase letter: T. But I have a trait with several associated types. Is it okay to use acronyms such as CD to represent, say, connection data? And I cannot use C, because it already exists (and also does not really portray "connection data"). I'd rather not use ConnectionData as that reads like a struct name. Should I not do this? I guess this question also applies to type parameters.


Solution

  • Where did you see that you should use shortcuts for associated types? They're commonly used for generic parameters (and even then, only when there is one or two), but not for associated types. Look in the standard library: there is no one-letter associated type. ConnectionData is the correct name.