Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACP: Chars::take_str #449

Open
dev-ardi opened this issue Sep 26, 2024 · 1 comment
Open

ACP: Chars::take_str #449

dev-ardi opened this issue Sep 26, 2024 · 1 comment
Labels
api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@dev-ardi
Copy link

Proposal

A fn in Chars<'a> that skips until it finds a specific char and returns the &'a str while it was skipping.

For example:

"I like bananas"
    ^ Chars is here 
let subslice = my_chars.take_str(' ');
assert_eq(subslice, "like");
"I like bananas"
          ^ Chars is here 

Problem statement

There's currently no ergonomic way of doing this, it's possible but not something that feels supported.

Motivating examples or use cases

While iterating over chars it's not the most ergonomic thing to find individual words, or to get subslices.

Solution sketch

fn take_str(&mut self) -> &str
@dev-ardi dev-ardi added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Sep 26, 2024
@BurntSushi
Copy link
Member

Please fill out the motivation section more. I would like to see a real example of its use.

It also looks like your prose description of its behavior doesn't match the behavior shown in your code snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

2 participants