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

add AsRef<[u8]> for both str and String #25162

Merged
merged 3 commits into from
May 9, 2015
Merged

Conversation

seanmonstar
Copy link
Contributor

r? @aturon

@alexcrichton
Copy link
Member

Does this compile when rebased on #25120? It makes the meaning of vec_of_strings.concat() ambiguous as it could return Vec<Vec<u8>> or a String

@seanmonstar
Copy link
Contributor Author

Ah carps, you're right, that does make it ambiguous. Possibilities:

  1. Scrap this idea. However, it feels right to be able to make APIs generic over bytes AsRef<[u8]>, and including strings would be an ergo win.
  2. Require vec_of_strings.concat() be explicit.
  3. Change the implementations of SliceConcatExt to 4 implementations, 1 for each [T], Vec<T>, str, and String, instead of relying on AsRef<U>.

@alexcrichton
Copy link
Member

After some discussion with @aturon he has convinced me that we definitely want the ability to add these AsRef implementations, and we can touch up SliceConcatExt for now by using Borrow as the bound on those generic impl blocks instead of AsRef (as str will never implement Borrow<[u8]> due to hashing differences).

That will be a breaking change but is likely to have very little fallout, so we'll probably include it for beta. Could you update this PR with that change?

@alexcrichton alexcrichton added the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 8, 2015
@seanmonstar
Copy link
Contributor Author

@alexcrichton updated, passes make check-stage1.

@alexcrichton
Copy link
Member

@bors: r+ 8e491ef p=50

Thanks @seanmonstar!

@bors
Copy link
Contributor

bors commented May 9, 2015

⌛ Testing commit 8e491ef with merge c033d98...

@bors bors merged commit 8e491ef into rust-lang:master May 9, 2015
@bluss
Copy link
Member

bluss commented May 11, 2015

Dabo on irc says something broke with .connect()

< Dabo> This used to work, but doesn't anymore with the latest nightly: 
              some_set.iter().collect::<Vec<_>>().connect(", ")
< Dabo> `type `collections::vec::Vec<&collections::string::String>` does not implement any 
              method in scope named `connect``
< Dabo> I have rustc 1.1.0-nightly (dc630d01e 2015-05-09) (built 2015-05-10)

daboross added a commit to daboross/zaldinar that referenced this pull request May 11, 2015
@daboross
Copy link
Contributor

Full code example that breaks: http://is.gd/vdlpTma

This isn't a major use-case I wouldn't think, but just noting an example of that here.

@seanmonstar
Copy link
Contributor Author

I forgot to include [breaking-change] in the last commit to :(

@alexcrichton
Copy link
Member

Adding beta-accepted as this has been merged into beta

@alexcrichton alexcrichton added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels May 11, 2015
@seanmonstar seanmonstar deleted the asref-bytes branch May 11, 2015 18:23
@brson brson added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-accepted Accepted for backporting to the compiler in the beta channel. labels May 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants