Skip to content

Implement From<{Rc,Arc}<str>> for [u8] counterpart #97425

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

Closed
wants to merge 1 commit into from

Conversation

nvzqz
Copy link
Contributor

@nvzqz nvzqz commented May 26, 2022

This enables safely converting from Arc<str> or Rc<str> to Arc<[u8]> or Rc<[u8]> respectively.

Currently the following steps are needed outside of the standard library:

fn from_str(s: Arc<str>) -> Arc<[u8]> {
    let len: usize = s.len();
    let ptr: *const u8 = Arc::into_raw(s).cast();
    let raw: *const [u8] = std::ptr::slice_from_raw_parts(ptr, len);
    unsafe { Arc::from_raw(raw) }
}

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 26, 2022
@rust-highfive
Copy link
Contributor

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Contributor

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 26, 2022
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking alloc v0.0.0 (/checkout/library/alloc)
    Checking cfg-if v0.1.10
    Checking adler v0.2.3
    Checking rustc-demangle v0.1.21
error[E0119]: conflicting implementations of trait `core::convert::From<rc::Rc<str>>` for type `rc::Rc<[u8]>`
     |
     |
1900 | impl From<Rc<str>> for Rc<[u8]> {
     | ------------------------------- first implementation here
...
1983 | impl From<Rc<str>> for Rc<[u8]> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `rc::Rc<[u8]>`

error[E0119]: conflicting implementations of trait `core::convert::From<sync::Arc<str>>` for type `sync::Arc<[u8]>`
     |
     |
2501 | impl From<Arc<str>> for Arc<[u8]> {
     | --------------------------------- first implementation here
...
2584 | impl From<Arc<str>> for Arc<[u8]> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `sync::Arc<[u8]>`
error[E0711]: feature `shared_from_str` is declared stable since 1.62.0, but was previously declared stable since 1.63.0
    --> library/alloc/src/rc.rs:1982:1
     |
     |
1982 | #[stable(feature = "shared_from_str", since = "1.62.0")]

error[E0711]: feature `shared_from_str` is declared stable since 1.62.0, but was previously declared stable since 1.63.0
    --> library/alloc/src/sync.rs:2583:1
     |
     |
2583 | #[stable(feature = "shared_from_str", since = "1.62.0")]

For more information about this error, try `rustc --explain E0119`.
error: could not compile `alloc` due to 4 previous errors
Build completed unsuccessfully in 0:01:39

@nvzqz
Copy link
Contributor Author

nvzqz commented May 26, 2022

Apparently this was already done in #96078! Thanks @udoprog!

@nvzqz nvzqz closed this May 26, 2022
@nvzqz nvzqz deleted the shared-from-str branch May 26, 2022 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants