&self -> to_*, self -> into_*, &mut self -> ??

The standard naming convention for functions is:

to_* (&self, ...);
into_* (self, ...);

what, if any, is the naming convention for (&mut self, ...) ?

See Naming - Rust API Guidelines (rust-lang.github.io).

I see

Prefix	Cost	Ownership
as_	Free	borrowed -> borrowed
to_	Expensive	borrowed -> borrowed
borrowed -> owned (non-Copy types)
owned -> owned (Copy types)
into_	Variable	owned -> owned (non-Copy types)

but it does not help me. Are you referring to a different section ?

You can use as_ or to_ for both &self and &mut self. The kind of borrow is not important — whether it is free is what determines the difference.

1 Like

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.