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

Implement Vec::drain, as_(mut_)view on the *Inner types, generic over Storage #500

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sosthene-nitrokey
Copy link
Contributor

This makes drain usable in the context of an implementation generic over the storage
This also makes it possible to get a *View in this same context

This could also be a way to "de-monomorphize" all the implementations of the Inner structs:

We could make all implementation define an inner function that is over a View type, and start the
implementation with this = self.as_(mut_)view, maybe for binary size and compilation time benefits. For example the implementation of VecInner::push could be:

    /// Appends an `item` to the back of the collection
    ///
    /// Returns back the `item` if the vector is full.
    pub fn push(&mut self, item: T) -> Result<(), T> {
        fn inner<T>(this: &mut VecView<T>, item: T) -> Result<(), T> {
            if this.len < this.storage_capacity() {
                unsafe { this.push_unchecked(item) }
                Ok(())
            } else {
                Err(item)
            }
        }
        inner(self.as_mut_view(), item)
    }

@sosthene-nitrokey sosthene-nitrokey changed the title Implement Vec::drain, as_(mut_)view the *Inner types, generic over Storage Implement Vec::drain, as_(mut_)view on the *Inner types, generic over Storage Jul 3, 2024
@sosthene-nitrokey
Copy link
Contributor Author

I checked with nightly, we can't do that with just a type Buffer<T>: Unsize<[T], because there is no implementation of Unsize<[T]> for [T], that's a shame. So even if Unsize gets stabilized, we'll have to keep all the manual conversion methods.

…torage`

This makes `drain` usable in the context of an implementation generic over the storage
This also makes it possible to get a `VecView` in this same context

This could also be a way to "de-monomorphize" all the implementations of the `Inner` structs:

We could make all implementation define an inner function that is over a `View` type, and start the
implementation with `this = self.as_(mut_)view`, maybe for binary size and compilation time benefits
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

Successfully merging this pull request may close these issues.

1 participant