Naming convention for to_... for compound type names (eg, FooBar)

What is the commonly used naming convention for to_...() for conversion to a type with a compound name? I can't seem to find any examples or relevant discussion.

More concretely, in the code:

pub(crate) trait Arithmetic: Copy + Sized {
  type ModInt: Copy + Sized + Eq; // opaque type
  fn to_modint(&self, n: u64) -> Self::ModInt;

Is to_modint(...) the usual idiom, or should it be to_mod_int(...), or something else?

If there ain't a clippy rule for it, I'm guessing you could go either way. My vote would be for the latter though. I mean just imagine - SuperAndIdioticallyLongName becomes to_superandidioticallylongname.
Also, I think in the Fuchsia project, for fidlgen, the latter rule is followed to convert camel-case to snake-case.

Here's a precedent:

That's the NonNull type becoming non_null in the method name.

Similarly, has the CStr type becoming c_str in the method name.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.