Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2580822

Browse files
committed
refactor: moved Vec impl Cow into cow.rs
1 parent 6bf9608 commit 2580822

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

library/alloc/src/vec/cow.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::borrow::Cow;
2+
use core::iter::{FromIterator};
3+
4+
use super::{Vec};
5+
6+
#[stable(feature = "cow_from_vec", since = "1.8.0")]
7+
impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
8+
fn from(s: &'a [T]) -> Cow<'a, [T]> {
9+
Cow::Borrowed(s)
10+
}
11+
}
12+
13+
#[stable(feature = "cow_from_vec", since = "1.8.0")]
14+
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
15+
fn from(v: Vec<T>) -> Cow<'a, [T]> {
16+
Cow::Owned(v)
17+
}
18+
}
19+
20+
#[stable(feature = "cow_from_vec_ref", since = "1.28.0")]
21+
impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {
22+
fn from(v: &'a Vec<T>) -> Cow<'a, [T]> {
23+
Cow::Borrowed(v.as_slice())
24+
}
25+
}
26+
27+
#[stable(feature = "rust1", since = "1.0.0")]
28+
impl<'a, T> FromIterator<T> for Cow<'a, [T]>
29+
where
30+
T: Clone,
31+
{
32+
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Cow<'a, [T]> {
33+
Cow::Owned(FromIterator::from_iter(it))
34+
}
35+
}

library/alloc/src/vec/mod.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub use self::drain::Drain;
8989

9090
mod drain;
9191

92+
mod cow;
93+
9294
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
9395
///
9496
/// # Examples
@@ -3013,41 +3015,6 @@ impl<T, A: Allocator, const N: usize> TryFrom<Vec<T, A>> for [T; N] {
30133015
}
30143016
}
30153017

3016-
////////////////////////////////////////////////////////////////////////////////
3017-
// Clone-on-write
3018-
////////////////////////////////////////////////////////////////////////////////
3019-
3020-
#[stable(feature = "cow_from_vec", since = "1.8.0")]
3021-
impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
3022-
fn from(s: &'a [T]) -> Cow<'a, [T]> {
3023-
Cow::Borrowed(s)
3024-
}
3025-
}
3026-
3027-
#[stable(feature = "cow_from_vec", since = "1.8.0")]
3028-
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
3029-
fn from(v: Vec<T>) -> Cow<'a, [T]> {
3030-
Cow::Owned(v)
3031-
}
3032-
}
3033-
3034-
#[stable(feature = "cow_from_vec_ref", since = "1.28.0")]
3035-
impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {
3036-
fn from(v: &'a Vec<T>) -> Cow<'a, [T]> {
3037-
Cow::Borrowed(v.as_slice())
3038-
}
3039-
}
3040-
3041-
#[stable(feature = "rust1", since = "1.0.0")]
3042-
impl<'a, T> FromIterator<T> for Cow<'a, [T]>
3043-
where
3044-
T: Clone,
3045-
{
3046-
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Cow<'a, [T]> {
3047-
Cow::Owned(FromIterator::from_iter(it))
3048-
}
3049-
}
3050-
30513018
////////////////////////////////////////////////////////////////////////////////
30523019
// Iterators
30533020
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)