rustonaut / vec1

Rust `Vec<T>` wrapper that gurantees to contain at least 1 element
Apache License 2.0
88 stars 15 forks source link

`into_vec` should be named `as_vec`, as it’s O(1) #12

Closed Profpatsch closed 5 years ago

Profpatsch commented 5 years ago

Rust has a convention for naming operations that convert data structures:

into_vec just returns the internally wrapped vec, so incurs no runtime overhead (the compiler uses the same memory representation for both). It should be renamed as_vec and into_vec deprecated.

rustonaut commented 5 years ago

I have to apologize for not responding for such a long time (thinks happened ¯_(ツ)_/¯).

vec.into_vec() is a named version of vec.into() for cases where just using Into is ambiguous for either the rust compiler or human reading the code. (I.e. it's a short form of <Vec1<T> as Into<Vec<T>>>::into(vec)).

Also I think you misunderstand how the naming schema works. It's based on the kind of operation done not the (time/memory) cost this operation causes. It should be more something on the line of:

Note that there are some exceptions:

rustonaut commented 5 years ago

Don't misunderstand:

Profpatsch commented 5 years ago

Ah, thank you for the in-depth explanation.

I think I saw the table at https://rust-lang-nursery.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv before I had actual knowledge about ownership and reduced it to complexity.