Use Self in implementations whenever possible #110

Closed
opened 2025-08-04 21:53:15 +00:00 by Vectornaut · 0 comments
Member

In the implementations of structures and traits, we should avoid repetition by using Self type alias whenever possible, as discussed in this comment and the following ones. This style seems to be used to some extent in the source code for the Rust standard library and for nalgebra. For example:

  • It's used for the return type, but not the returned structure, in Vec::new.
  • It's used for the return type, but not the returned structure, in ColPivQR::new from nalgebra.
  • It's not used at all in BTreeSet::new_in—which is newly added code, and therefore might reflect current conventions.

The main downside I see to this style is that it can make the source harder to navigate, because it's context-dependent.

In the implementations of structures and traits, we should avoid repetition by using `Self` type alias whenever possible, as discussed in [this comment](https://code.studioinfinity.org/StudioInfinity/dyna3/pulls/108#issuecomment-3163) and the following ones. This style seems to be used to some extent in the source code for the Rust standard library and for nalgebra. For example: - It's used for the return type, but not the returned structure, in [`Vec::new`](https://doc.rust-lang.org/src/alloc/vec/mod.rs.html#434). - It's used for the return type, but not the returned structure, in [`ColPivQR::new`](https://docs.rs/nalgebra/latest/src/nalgebra/linalg/col_piv_qr.rs.html#59-92`) from nalgebra. - It's not used at all in [`BTreeSet::new_in`](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#364)—which is newly added code, and therefore might reflect current conventions. The main downside I see to this style is that it can make the source harder to navigate, because it's context-dependent.
Vectornaut added the
maintenance
label 2025-08-04 21:53:26 +00:00
glen closed this issue 2025-08-07 23:24:10 +00:00
Sign in to join this conversation.
No description provided.