Skip to content

Tracking issue for str_char stabilization #27754

Closed
@aturon

Description

@aturon
Member

The str type offers a number of char-oriented methods, many of which can be replaced by uses of char_indices.

It's not clear how widely used these methods are, or whether there are significant downsides over using char_indices. This API area needs a comprehensive re-evaluation.

cc @SimonSapin

Activity

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
B-unstableBlocker: Implemented in the nightly compiler and unstable.
on Aug 12, 2015
murarth

murarth commented on Oct 29, 2015

@murarth
Contributor

This may be obvious, but I just want to point out that is_char_boundary is much more efficient than a solution involving iteration over char_indices. If nothing else under this feature gate is stabilized, I think at least this should method should be.

SimonSapin

SimonSapin commented on Dec 28, 2015

@SimonSapin
Contributor

I’ve used str::is_char_boundary in low-level string manipulation: rust-lang/rfcs#1432. In this case I’d like this functionality to move into std where stability is not a problem, but the fact remains that is_char_boundary is important in unsafe code dealing with strings.

Now, most (all?) of its uses are inside assert!, which is possibly to do in stable Rust by relying on the side effect of some other operation. For example, s[..i]; is equivalent to assert!(s.is_char_boundary(i)); but it’s much less self-explanatory. It definitely needs a comment.

I’d like to nominate is_char_boundary for stabilization. It’s needed internally anyway, so it’s not like it has extra maintenance cost.

(I care less about the other str_char methods. I think they predate and are largely made obsolete by external iterators.)

huonw

huonw commented on Jan 5, 2016

@huonw
Member

Some discussion about CharRange on #9387.

aturon

aturon commented on Jan 27, 2016

@aturon
MemberAuthor

Nominating for discussion -- need a direction here.

dhardy

dhardy commented on Jan 27, 2016

@dhardy
Contributor

I found a use for is_char_boundary recently, in order to implement a variant of truncate:

fn truncate_at_boundary<'a>(s: &'a str, len: usize) -> &'a str {
    let mut len = min(len, s.len());
    while !s.is_char_boundary(len) { len -= 1; }
    &s[0..len]
}

on play.rust-lang.org

bluss

bluss commented on Jan 27, 2016

@bluss
Member

is_char_boundary is very useful, as soon as you implement your own low level string utils. I've replicated in stable rust for use as well.

alexcrichton

alexcrichton commented on Jan 29, 2016

@alexcrichton
Member

Unfortunately the libs team didn't get a chance to talk about this in terms of stabilization for 1.8, but I'm going to leave the nominated tag as I think we should chat about this regardless.

alexcrichton

alexcrichton commented on Feb 11, 2016

@alexcrichton
Member

The libs team discussed this during triage today, and the conclusion was:

  • It seems prudent to stabilize is_char_boundary (definitely seems desired at least)
  • We may be able to deprecate all other methods, they're all expressible in terms of slicing an iterators, and there doesn't seem to be much of a burning desire to keep them!

21 remaining items

Loading
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

    B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @thijsc@alexcrichton@dhardy@SimonSapin@BurntSushi

        Issue actions

          Tracking issue for `str_char` stabilization · Issue #27754 · rust-lang/rust