Skip to content

Commit f5d5b8a

Browse files
Adding COOP_PREFERRED to Cow, ToOwned, String.
1 parent 4206d09 commit f5d5b8a

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

library/alloc/src/string.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,7 @@ where
21282128

21292129
#[cfg(not(no_global_oom_handling))]
21302130
#[stable(feature = "herd_cows", since = "1.19.0")]
2131-
impl<'a, const COOP_PREFERRED: bool> FromIterator<Cow<'a, str>> for String<COOP_PREFERRED>
2131+
impl<'a, const COOP_PREFERRED: bool> FromIterator<Cow<'a, str, COOP_PREFERRED>> for String<COOP_PREFERRED>
21322132
where
21332133
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
21342134
{
@@ -2238,16 +2238,16 @@ where
22382238

22392239
#[cfg(not(no_global_oom_handling))]
22402240
#[stable(feature = "herd_cows", since = "1.19.0")]
2241-
impl<'a, const COOP_PREFERRED: bool> Extend<Cow<'a, str>> for String<COOP_PREFERRED>
2241+
impl<'a, const COOP_PREFERRED: bool> Extend<Cow<'a, str, COOP_PREFERRED>> for String<COOP_PREFERRED>
22422242
where
22432243
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
22442244
{
2245-
fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I) {
2245+
fn extend<I: IntoIterator<Item = Cow<'a, str, COOP_PREFERRED>>>(&mut self, iter: I) {
22462246
iter.into_iter().for_each(move |s| self.push_str(&s));
22472247
}
22482248

22492249
#[inline]
2250-
fn extend_one(&mut self, s: Cow<'a, str>) {
2250+
fn extend_one(&mut self, s: Cow<'a, str, COOP_PREFERRED>) {
22512251
self.push_str(&s);
22522252
}
22532253
}
@@ -2789,7 +2789,7 @@ where
27892789

27902790
#[cfg(not(no_global_oom_handling))]
27912791
#[stable(feature = "cow_str_to_string_specialization", since = "1.17.0")]
2792-
impl<const COOP_PREFERRED: bool> ToString<COOP_PREFERRED> for Cow<'_, str>
2792+
impl<const COOP_PREFERRED: bool> ToString<COOP_PREFERRED> for Cow<'_, str, COOP_PREFERRED>
27932793
where
27942794
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
27952795
{
@@ -2940,7 +2940,7 @@ where
29402940

29412941
#[cfg(not(no_global_oom_handling))]
29422942
#[stable(feature = "string_from_cow_str", since = "1.14.0")]
2943-
impl<'a, const COOP_PREFERRED: bool> From<Cow<'a, str>> for String<COOP_PREFERRED>
2943+
impl<'a, const COOP_PREFERRED: bool> From<Cow<'a, str, COOP_PREFERRED>> for String<COOP_PREFERRED>
29442944
where
29452945
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
29462946
{
@@ -2967,7 +2967,10 @@ where
29672967

29682968
#[cfg(not(no_global_oom_handling))]
29692969
#[stable(feature = "rust1", since = "1.0.0")]
2970-
impl<'a> From<&'a str> for Cow<'a, str> {
2970+
impl<'a, const COOP_PREFERRED: bool> From<&'a str> for Cow<'a, str, COOP_PREFERRED>
2971+
where
2972+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
2973+
{
29712974
/// Converts a string slice into a [`Borrowed`] variant.
29722975
/// No heap allocation is performed, and the string
29732976
/// is not copied.
@@ -2981,14 +2984,14 @@ impl<'a> From<&'a str> for Cow<'a, str> {
29812984
///
29822985
/// [`Borrowed`]: crate::borrow::Cow::Borrowed "borrow::Cow::Borrowed"
29832986
#[inline]
2984-
fn from(s: &'a str) -> Cow<'a, str> {
2987+
fn from(s: &'a str) -> Cow<'a, str, COOP_PREFERRED> {
29852988
Cow::Borrowed(s)
29862989
}
29872990
}
29882991

29892992
#[cfg(not(no_global_oom_handling))]
29902993
#[stable(feature = "rust1", since = "1.0.0")]
2991-
impl<'a, const COOP_PREFERRED: bool> From<String<COOP_PREFERRED>> for Cow<'a, str>
2994+
impl<'a, const COOP_PREFERRED: bool> From<String<COOP_PREFERRED>> for Cow<'a, str, COOP_PREFERRED>
29922995
where
29932996
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
29942997
{
@@ -3039,16 +3042,22 @@ where
30393042

30403043
#[cfg(not(no_global_oom_handling))]
30413044
#[stable(feature = "cow_str_from_iter", since = "1.12.0")]
3042-
impl<'a> FromIterator<char> for Cow<'a, str> {
3043-
fn from_iter<I: IntoIterator<Item = char>>(it: I) -> Cow<'a, str> {
3045+
impl<'a, const COOP_PREFERRED: bool> FromIterator<char> for Cow<'a, str, COOP_PREFERRED>
3046+
where
3047+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
3048+
{
3049+
fn from_iter<I: IntoIterator<Item = char>>(it: I) -> Cow<'a, str, COOP_PREFERRED> {
30443050
Cow::Owned(FromIterator::from_iter(it))
30453051
}
30463052
}
30473053

30483054
#[cfg(not(no_global_oom_handling))]
30493055
#[stable(feature = "cow_str_from_iter", since = "1.12.0")]
3050-
impl<'a, 'b> FromIterator<&'b str> for Cow<'a, str> {
3051-
fn from_iter<I: IntoIterator<Item = &'b str>>(it: I) -> Cow<'a, str> {
3056+
impl<'a, 'b, const COOP_PREFERRED: bool> FromIterator<&'b str> for Cow<'a, str, COOP_PREFERRED>
3057+
where
3058+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
3059+
{
3060+
fn from_iter<I: IntoIterator<Item = &'b str>>(it: I) -> Cow<'a, str, COOP_PREFERRED> {
30523061
Cow::Owned(FromIterator::from_iter(it))
30533062
}
30543063
}

0 commit comments

Comments
 (0)