With the exception of drop
, there aren't any free functions in the prelude (I suspected this, and a quick check confirmed it). Some traits that are applicable to nearly everything, like the associated traits for derive
s, From
/Into
, ToOwned
, etc. are also in the prelude. To me, that they're applicable to just about any program someone might want to write is the reason they are present. drop
, on the other hand, is not as widely applicable. I just did a quick rg "drop\("
over the directory I keep all my projects in; the only match was in standback
, which is derived from stdlib. Said another way, I don't call drop
anywhere at all in any of my Rust code.
Performing the same (limited) analysis for std::mem::{swap, replace, take}
, there is all of one match wherein I swap a telemetry log out for an empty one. Checking for as_mut()
, as_ref()
, into()
/::into()
, into_iter()
, iter()
, to_owned()
, to_string()
, and ::from(_)
yields a cumulative 607 matches (nb: not lines). This does not include fully-qualified syntax for most of the methods. For reference, these projects combine to 26,834 lines of Rust code per tokei
.
Macros are a different story that really isn't applicable here, as nothing being talked about is macros.
So as I've stated previously in other threads, I suppose the reason I'm opposed to it is primarily the lack of real-world usage in the areas of the projects I have cloned locally. I also personally believe that having the mem::
prefix is preferred, but that's a style concern. I understand that other use cases would benefit from these methods being in the prelude in the same way that drop
is, but ~1/27,000 is hardly comparable to ~1/44 in my real-world codebases.
Now that I am finishing typing this out, I realize that it's not really an argument against free functions being in the prelude, just that it's not used enough in my experience. But regardless, hopefully this helps somehow.
As a side note, I have excluded the rust and standback repositories that I have cloned locally from this data, as I'm fairly certain they are nowhere near representative of the average codebase.