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

More str method conversion and cleanup. #7060

Closed
wants to merge 15 commits into from
Closed

Conversation

huonw
Copy link
Member

@huonw huonw commented Jun 11, 2013

There are now only half-a-dozen or so functions left std::str that should be methods.

Highlights:

  • .substr was removed, since most of the uses of it in the code base were actually incorrect (it had a weird mixing of a byte index and a unicode character count), adding .slice_chars if one wants to handle characters, and the normal .slice method to handle bytes.
  • Code duplication between the two impls for connect and concat was removed via a new Str trait, that is purely designed to allow an explicit -> &str conversion (.as_slice())
  • Deconfuse the 5 different functions for converting to [u8] (3 of which had actually incorrect documentation: implying that they didn't have the null terminator), into 3: as_bytes (all strings), as_bytes_with_null (&'static str, @str and ~str) and as_bytes_with_null_consume (~str). None of these allocate, unlike the old versions.

(cc @thestinger)

huonw added 14 commits June 12, 2013 12:21
…s_bytes_with_null[_consume]().

The first acts on &str and is not nul-terminated, the last two act on strings
that are always null terminated (&'static str, ~str and @str).
…e_chars.

The confusing mixture of byte index and character count meant that every
use of .substr was incorrect; replaced by slice_chars which only uses
character indices. The old behaviour of `.substr(start, n)` can be emulated
via `.slice_from(start).slice_chars(0, n)`.
The Str trait collects the various strings types and provides a method
for coercing to a slice, so that functions and impls can be written for
generic types containing strings (e.g. &[~str], &[&str], ...) without
having to write one for each string type (assuming that the impl only
needs a slice).
@erickt
Copy link
Contributor

erickt commented Jun 12, 2013

@huonw: Just to let you know, I'm also working on some string cleanup in #7039.

bors added a commit that referenced this pull request Jun 12, 2013
There are now only half-a-dozen or so functions left `std::str` that should be methods.

Highlights:
- `.substr` was removed, since most of the uses of it in the code base were actually incorrect (it had a weird mixing of a byte index and a unicode character count), adding `.slice_chars` if one wants to handle characters, and the normal `.slice` method to handle bytes.
- Code duplication between the two impls for `connect` and `concat` was removed via a new `Str` trait, that is purely designed to allow an explicit -> `&str` conversion (`.as_slice()`)
- Deconfuse the 5 different functions for converting to `[u8]` (3 of which had actually incorrect documentation: implying that they didn't have the null terminator), into 3: `as_bytes` (all strings), `as_bytes_with_null` (`&'static str`, `@str` and `~str`) and `as_bytes_with_null_consume` (`~str`). None of these allocate, unlike the old versions.

(cc @thestinger)
@bors bors closed this Jun 12, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 22, 2021
…fn, r=flip1995

Remove `debug_assert` from `panic_in_result_fn`

I couldn't find any documentation on `debug_assert` that should be remove.
In my humble opinion, I would also like to argue that `todo` and `unreachable` shouldn't trigger this lint?

Related: rust-lang/rust-clippy#6082

r? `@flip1995`

changelog: Change `panic_in_result_fn` to ignore `debug_assert` and co macros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants