Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are inherent associated functions of ArrayVec implemented via calls to trait-associated functions of ArrayVecImpl and not vice versa? #228

Closed
JohnScience opened this issue Oct 13, 2022 · 1 comment

Comments

@JohnScience
Copy link

JohnScience commented Oct 13, 2022

Example:

/// Return a mutable slice containing all elements of the vector.
pub fn as_mut_slice(&mut self) -> &mut [T] {
    ArrayVecImpl::as_mut_slice(self)
}

AFAIK, const trait implementation is not landing soon. If ArrayVecImpl::as_mut_slice is defined via the call to the inherent function instead (i.e. if we reverse the implementation dependency), it will be possible to have easier feature-gated support for the const inherent associated function. Instead of the dependence on both const_trait_impl and const_mut_refs features there will be the dependency only on the latter.

I guess it may be fine if you don't want to offer a feature-gated support for nightly const_mut_refs. However, I wouldn't mind to help you with reversing the dependency and opt-in support for the aforementioned nightly features. There's a popular crate const_fn that can help provide such support cleaner.

@JohnScience JohnScience changed the title Why are inherent associated methods of ArrayVec implemented via calls to trait-associated methods of ArrayVecImpl and not vice versa? Why are inherent associated functions of ArrayVec implemented via calls to trait-associated functions of ArrayVecImpl and not vice versa? Oct 13, 2022
@bluss
Copy link
Owner

bluss commented Jun 12, 2023

The idea for ArrayVecImpl is to pool common code - common to ArrayVec and ArrayVecCopy (when that exists), I don't think you can reverse this

@bluss bluss closed this as completed Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants