Skip to content

Flesh out functionality #18

Open
Open

Description

@FintanH

We should flesh out the functionality of nonempty. A lot of it would just be the Vec implementation.
Enumerating these for clarity and also to comment on which ones we may not want:

  • append
  • as_mut_ptr N/A (memory is not contiguous)
  • as_mut_slice N/A
  • as_ptr N/A
  • as_slice N/A
  • capacity
  • chunks
  • chunks_exact
  • chunks_exact_mut
  • chunks_mut
  • clone_from_slice - we use from_slice, we should rename This doesn't make sense either since it's just copying a slice's contents in, but we can't guarantee a length of 1 without panicing.
  • concat
  • connect
  • contains
  • copy_from_slice - we have from_slice but a Copy version would be good Looking into the semantics of this, I think it doesn't suit NonEmpty after all.
  • copy_within
  • clear - we probably don't want this
  • dedup
  • dedup_by
  • drain - wouldn't make sense for NonEmpty unless it returned a Vec rather than Drain
  • drain_filter - same as above
  • ends_with
  • eq_ignore_ascii_case
  • extend_from_slice
  • first
  • first_mut
  • from_raw_parts - this seems unecessary
  • get
  • get_mut
  • get_unchecked
  • get_unchecked_mut
  • insert
  • into_boxed_slice
  • into_raw_parts - not sure about this one
  • is_ascii
  • is_empty
  • is_sorted
  • is_sorted_by_key
  • iter
  • iter_mut
  • join
  • last
  • last_mut
  • leak - seems specialised
  • len
  • make_ascii_lowercase
  • make_ascii_uppercase
  • new
  • partition_at_index
  • partition_at_index_by
  • partition_at_index_by_key
  • partition_deup
  • partition_deup_by
  • partition_deup_by_key
  • pop
  • push
  • rchunks
  • rchunks_exact
  • rchunks_exact_mut
  • rchunks_mut
  • remove - should give back Vec
  • remove_item - should give back Vec
  • repeat
  • reserve
  • reserve_exact
  • resize - possibly just work on the tail Vec
  • resize_default
  • resize_wtih
  • retain - unsure if this should be kept
  • reverse
  • rotate_left
  • rotate_right
  • rsplit
  • rsplit_mut
  • rsplitn
  • rsplitn_mut
  • set_len
  • shrink_to - should be greater than 1
  • shrink_to_fit
  • sort
  • sort_by
  • sort_by_cahced_key
  • sort_by_key
  • sort_unstable
  • sort_unstable_by
  • sort_unstable_by_key
  • splice
  • split
  • split_at
  • split_at_mut
  • split_first
  • split_first_mut
  • split_last
  • split_last
  • split_last_mut
  • split_mut
  • split_off
  • splitn
  • splitn_mut
  • starts_with
  • swap
  • swap_with_slice
  • to_ascii_lowercase
  • to_ascii_uppercase
  • to_vec - the Into impl does this
  • try_reserve
  • try_reserve_exact
  • windows
  • with_capacity
  • From<NonEmpty<T>> for Vec<T> - Implement and test IntoIterator #17 (comment)

Activity

  1. FintanH commented on Mar 17, 2020

    @FintanH
    CollaboratorAuthor

    Hmmmm so something I'd like to discuss is the functions that come "Methods from Deref<Target = [T]>". Is this something that's possible with NonEmpty? Also, this makes me think, could we implement Deref<Target=Vec<T>>? 🤔

    Otherwise, I think the way to go about it is go through the list of functions and see if they're possible to implement.

  2. FintanH commented on Mar 17, 2020

    @FintanH
    CollaboratorAuthor

    As discussed async, we should use https://doc.rust-lang.org/std/num/struct.NonZeroUsize.html for things that take a length, e.g. with_capacity

  3. FintanH commented on Mar 17, 2020

    @FintanH
    CollaboratorAuthor

    Something I'd also be interested in is split functions that own the T, I'm not sure if this is possible though. I tend to split and consume, but I end up having to clone :/

  4. fritzrehde commented on Dec 9, 2023

    @fritzrehde

    In the checklist it says as_mut_slice is implemented, but I can't find that method anywhere in the repo or in the documentation.

  5. cloudhead commented on Dec 19, 2023

    @cloudhead
    Owner

    I think it's checked for the same reason as_slice is checked: it's actually not possible to implement these since the memory isn't contiguous. I'll update the todo.

  6. bbstilson commented on Mar 17, 2026

    @bbstilson

    @FintanH is it cool if I open a PR for with_capacity? I have a use-case that would benefit, and I'm happy to contribute 🙂

    Branch is up here: https://github.com/cloudhead/nonempty/compare/master...bbstilson:nonempty:feature/new_with_capacity?expand=1

  7. FintanH commented on Mar 17, 2026

    @FintanH
    CollaboratorAuthor

    Hey @bbstilson! Yes please do, I’ll get around to merging it when I can ☺️

  8. FintanH commented on Mar 17, 2026

    @FintanH
    CollaboratorAuthor

    I’m just looking at your branch and have two questions:

    • Why is the capacity not allowed to be zero?
    • If it’s not allowed to be zero, than why not take NonZero?
  9. bbstilson commented on Mar 17, 2026

    @bbstilson

    I’m just looking at your branch and have two questions:

    * Why is the capacity not allowed to be zero?
    
    * If it’s not allowed to be zero, than why not take NonZero?
    

    Great questions. I think my brain just checked out for a bit because I originally implemented with NonZeroUsize, then deleted it. Anyways, I added it back in and opened a PR haha: #84

  10. bbstilson commented on Mar 21, 2026

    @bbstilson

    How desirable is it to modify the NonEmpty struct such that memory is contiguous? The current implementation prevents a lot of Vec operations (all the chunks, for example).

    (edit)

    I did this locally (happy to push a branch); it was pretty straightforward. The biggest consequence is constructors are no longer const compatible because you can't instantiate a vec at compile time.

  11. bbstilson commented on Apr 6, 2026

    @bbstilson

    @FintanH bumping ☝🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions