-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: From<&[T]> for Rc<[T]> + From<&str> for Rc<str> #1844
Comments
It seems that with the recent conversation about field re-ordering, this could fail if random ordering were implemented, unless |
@seanmonstar Yes, that'd be the case, but then, |
Non-allocating |
@Stebalien unless I'm mistaken, since the @seanmonstar Maybe |
Mazdak Farrokhzad <notifications@github.com> writes:
@Stebalien unless I'm mistaken, since the `strong: Cell<usize>` and `weak: : Cell<usize>` refcounts are part of the `RcBox` that gets heap allocated... then the allocated space for `String` would either have to be reallocated, or you'd have to have separate allocations for the refcounts and for the data, which would add overhead to the rest of `Rc`. The same should apply to `Vec<T>`.
Ah. Good point.
|
Also do note that edit: okay, I guess |
Future allocator trait support may make things like this easier to do safely. |
@apasel422 but that should be mainly an implementation detail, no? i.e: it doesn't change the API... |
Closing this now that the RFC has been made. |
liballoc already has the following defined for
Rc<str>
:but it is gated under the feature
rustc_private
, which will never be stabilized.It would be useful to provide
From<str> for Rc<[T]>
andFrom<&str> for Rc<str>
implementations where the latter has use cases such as string interning (for example using:HashSet<Rc<str>>
).A quick implementation would be:
The text was updated successfully, but these errors were encountered: