Skip to content

VecDeque should support splice / extend_front #69939

Closed

Description

@Boscop

VecDeque should support splice for convenience.
(SliceDeque supports it, but it doesn't build on wasm and seems kind of abandoned (several unmerged PRs with no updates).)

VecDeque should also support extend_front (like repeated push_front from an iterator. Compared to calling q.splice(..0, iter), the elements added with q.extend_front(iter) would be in reverse order).

Activity

  1. added
    A-collectionsArea: `std::collections` (prefer A-binaryheap, A-btree, A-hashtable, A-linkedlist, A-vecdeque)
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    T-libs-api[DEPRECATED; DO NOT USE]
    on Mar 11, 2020
  2. cynecx commented on Dec 23, 2020

    @cynecx
    Contributor

    I had to switch over to using a Vec because I couldn't efficiently insert multiple items into a VecDeque. Having a splice method would've been really useful. If I can find some time these days, I might be able to work on a PR.

  3. tomkarw commented on Mar 28, 2022

    @tomkarw

    @rustbot claim

  4. Boscop commented on May 11, 2022

    @Boscop
    Author

    @tomkarw Thanks for working on this. Btw, what's the current status? :)

  5. tomkarw commented on Jul 16, 2022

    @tomkarw

    Sorry for the late response, apparently I don't get GitHub notification via email.

    TBH, I thought it will be easier. The unsafe code needed kinda scared me, and I got a job 4 days after claiming this.
    I'll try to revisit it now, but will probably look for a mentor/guidance.

  6. drwilco commented on Apr 25, 2023

    @drwilco

    And what about a .prepend() to mirror .append()?

  7. qvignaud commented on Jun 10, 2024

    @qvignaud

    Hi, I just found out I'm encountering a case where prepend() and/or extend_front() methods on VecDeque could be really useful.
    I'm doing the work by iterating over other vector and push_front repeatedly, but that feels not idiomatic and I guess not optimal at all.

    If no one is available for this I might take a look at some point.

  8. jnb commented on Aug 13, 2024

    @jnb

    +1 for implementing this. Repeatedly calling push_front has a significant performance impact for my use-case, so I ended-up hacking something together on top of a Vec.

  9. nhtyy commented on Dec 12, 2024

    @nhtyy

    I wonder what the blockers are here? I might give implementing prepend a shot this weekend.

  10. tomkarw commented on Dec 13, 2024

    @tomkarw

    No blockers, just lack of time. Feel free to pick it up, I'll be happy to see it implemented.

  11. jlnstrk commented on Mar 26, 2025

    @jlnstrk

    For the simple case of trying to avoid repeated shifts on insert into the middle, the following should add only O(2n+m) to the complexity of extend(), where n is length pre-insert and m is length of iter.

    use std::collections::VecDeque;
    
    trait VecDequeExt<T> {
        fn insert_iter<I>(&mut self, index: usize, iter: I) where 
            I: IntoIterator<Item = T>;
    }
    
    impl<T> VecDequeExt<T> for VecDeque<T> {
        fn insert_iter<I>(&mut self, index: usize, iter: I) where 
                I: IntoIterator<Item = T> {
            let n = self.len() - index;
            self.rotate_right(n);
            self.extend(iter);
            self.rotate_left(n);
        }
    }
    
    fn main() {
        let mut deque = VecDeque::new();
        deque.push_back(0);
        deque.push_back(1);
        deque.push_back(4);
        deque.push_back(5);
        
        deque.insert_iter(2, vec![2, 3]);
        assert_eq!(deque.into_iter().collect::<Vec<_>>(), vec![0, 1, 2, 3, 4, 5]);
    }
  12. antonilol commented on Sep 22, 2025

    @antonilol
    Contributor

    @rustbot claim

  13. antonilol commented on Oct 30, 2025

    @antonilol
    Contributor

    tracking issue: #146975, related PRs are linked there if people here want to check them out

  14. added 3 commits that reference this issue on Nov 6, 2025
  15. added a commit that references this issue on Nov 6, 2025
  16. added a commit that references this issue on Nov 6, 2025
  17. added a commit that references this issue on Nov 30, 2025
  18. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  19. added
    A-vecdequeArea: `std::collections::VecDeque`
    and removed
    A-collectionsArea: `std::collections` (prefer A-binaryheap, A-btree, A-hashtable, A-linkedlist, A-vecdeque)
    on Nov 2, 2026
  20. Dylan-DPC commented on Nov 7, 2026

    @Dylan-DPC
    Member

    Closing this in favour of the tracking issue #146975

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

Metadata

Metadata

Assignees

Labels

A-vecdequeArea: `std::collections::VecDeque`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions