Skip to content

dlist.split_off(dlist.len()) should not panic #22244

Closed
@mbrubeck

Description

@mbrubeck

Currently, Dlist::split_off requires its argument to be strictly less than the length of the list, which means the following function panics when passed a one-element list. Instead, it should leave the original list unmodified and return an empty list:

fn split_head<T>(list: &mut DList<T>) -> DList<T> {
    list.split_off(1)
}

In contrast, Vec::split_off does allow self.len() as a valid argument, so the above code works as desired if you replace DList with Vec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions