Skip to content

Tracking Issue for split_at_checked #119128

Closed

Description

Feature gate: #![feature(split_at_checked)].

This is a tracking issue for the addition of split_at_checked and split_at_mut_checked methods to [T] and str types which are non-panicking versions of split_at and split_at_mut methods. Rather than panicking when spit index is out of range (like split_at does), the methods return None.

Public API

impl<T> [T] {
    pub fn split_at_checked(&self, mid: usize) -> Option<(&[T], &[T])>;
    pub fn split_at_mut_checked(&self, mid: usize) -> Option<(&[T], &[T])>;
}

impl str {
    pub fn split_at_checked(&self, mid: usize) -> Option<(&str, &str)>;
    pub fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&str, &str)>;
}

Steps / History

Unresolved Questions

Name of the methods. Some possibilities (suggested in ACP discussion):

  1. split_at_checked and split_at_mut_checked — follows naming of split_at_unchecked and split_at_mut_unchecked. Using suffix makes the names sort nicely together.
  2. checked_split_at and checked_split_at_mut — follows naming convention of arithmetic types (e.g. checked_add). Those new functions serve similar purpose as checked arithmetic operations.
  3. try_split_at and try_split_at_mut — follows naming of various fallible methods such as try_from, try_new, try_for_each etc. Shortest of the three suggestions.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

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

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: A tracking issue for an RFC or an unstable feature.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions