Skip to content

Commit a1cf8c7

Browse files
committed
MAINT: Use private (not visible) type params for Vec/Rc<Vec>
Related to #299
1 parent 0e45ce1 commit a1cf8c7

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/data_traits.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use {
1515
ArrayBase,
1616
Dimension,
1717
ViewRepr,
18+
OwnedRepr,
19+
OwnedRcRepr,
1820
};
1921

2022
/// Array representation trait.
@@ -68,15 +70,15 @@ pub unsafe trait DataClone : Data {
6870
}
6971
}
7072

71-
unsafe impl<A> Data for Rc<Vec<A>> {
73+
unsafe impl<A> Data for OwnedRcRepr<A> {
7274
type Elem = A;
7375
fn _data_slice(&self) -> &[A] {
7476
self
7577
}
7678
}
7779

7880
// NOTE: Copy on write
79-
unsafe impl<A> DataMut for Rc<Vec<A>>
81+
unsafe impl<A> DataMut for OwnedRcRepr<A>
8082
where A: Clone
8183
{
8284
fn ensure_unique<D>(self_: &mut ArrayBase<Self, D>)
@@ -112,23 +114,23 @@ unsafe impl<A> DataMut for Rc<Vec<A>>
112114
}
113115
}
114116

115-
unsafe impl<A> DataClone for Rc<Vec<A>> {
117+
unsafe impl<A> DataClone for OwnedRcRepr<A> {
116118
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
117119
// pointer is preserved
118120
(self.clone(), ptr)
119121
}
120122
}
121123

122-
unsafe impl<A> Data for Vec<A> {
124+
unsafe impl<A> Data for OwnedRepr<A> {
123125
type Elem = A;
124126
fn _data_slice(&self) -> &[A] {
125127
self
126128
}
127129
}
128130

129-
unsafe impl<A> DataMut for Vec<A> { }
131+
unsafe impl<A> DataMut for OwnedRepr<A> { }
130132

131-
unsafe impl<A> DataClone for Vec<A>
133+
unsafe impl<A> DataClone for OwnedRepr<A>
132134
where A: Clone
133135
{
134136
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
@@ -185,7 +187,7 @@ pub unsafe trait DataOwned : Data {
185187
#[doc(hidden)]
186188
fn new(elements: Vec<Self::Elem>) -> Self;
187189
#[doc(hidden)]
188-
fn into_shared(self) -> Rc<Vec<Self::Elem>>;
190+
fn into_shared(self) -> OwnedRcRepr<Self::Elem>;
189191
}
190192

191193
/// Array representation trait.
@@ -195,23 +197,23 @@ pub unsafe trait DataOwned : Data {
195197
/// ***Internal trait, see `Data`.***
196198
pub unsafe trait DataShared : Clone + DataClone { }
197199

198-
unsafe impl<A> DataShared for Rc<Vec<A>> {}
200+
unsafe impl<A> DataShared for OwnedRcRepr<A> {}
199201
unsafe impl<'a, A> DataShared for ViewRepr<&'a A> {}
200202

201-
unsafe impl<A> DataOwned for Vec<A> {
203+
unsafe impl<A> DataOwned for OwnedRepr<A> {
202204
fn new(elements: Vec<A>) -> Self {
203205
elements
204206
}
205-
fn into_shared(self) -> Rc<Vec<A>> {
207+
fn into_shared(self) -> OwnedRcRepr<A> {
206208
Rc::new(self)
207209
}
208210
}
209211

210-
unsafe impl<A> DataOwned for Rc<Vec<A>> {
212+
unsafe impl<A> DataOwned for OwnedRcRepr<A> {
211213
fn new(elements: Vec<A>) -> Self {
212214
Rc::new(elements)
213215
}
214-
fn into_shared(self) -> Rc<Vec<A>> {
216+
fn into_shared(self) -> OwnedRcRepr<A> {
215217
self
216218
}
217219
}

src/impl_owned_array.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
use std::rc::Rc;
33

44
use imp_prelude::*;
5+
use {
6+
OwnedRepr,
7+
OwnedRcRepr,
8+
};
59

6-
impl<A, D> ArrayBase<Vec<A>, D>
10+
impl<A, D> ArrayBase<OwnedRepr<A>, D>
711
where D: Dimension
812
{
913
/// Return a vector of the elements in the array, in the way they are
@@ -17,7 +21,7 @@ impl<A, D> ArrayBase<Vec<A>, D>
1721
}
1822

1923
// RcArray
20-
impl<A, D> ArrayBase<Rc<Vec<A>>, D>
24+
impl<A, D> ArrayBase<OwnedRcRepr<A>, D>
2125
where A: Clone,
2226
D: Dimension
2327
{

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ pub struct ArrayBase<S, D>
504504
/// An array where the data has shared ownership and is copy on write.
505505
/// It can act as both an owner as the data as well as a shared reference (view
506506
/// like).
507-
pub type RcArray<A, D> = ArrayBase<Rc<Vec<A>>, D>;
507+
pub type RcArray<A, D> = ArrayBase<OwnedRcRepr<A>, D>;
508508

509509
/// An array that owns its data uniquely.
510510
///
@@ -522,7 +522,7 @@ pub type RcArray<A, D> = ArrayBase<Rc<Vec<A>>, D>;
522522
/// [`Array1`](Array1.t.html),
523523
/// [`Array2`](Array2.t.html),
524524
/// [`Array3`](Array3.t.html) and so on.
525-
pub type Array<A, D> = ArrayBase<Vec<A>, D>;
525+
pub type Array<A, D> = ArrayBase<OwnedRepr<A>, D>;
526526

527527
/// A lightweight array view.
528528
///
@@ -547,6 +547,12 @@ pub type ArrayView<'a, A, D> = ArrayBase<ViewRepr<&'a A>, D>;
547547
/// [ab]: struct.ArrayBase.html
548548
pub type ArrayViewMut<'a, A, D> = ArrayBase<ViewRepr<&'a mut A>, D>;
549549

550+
/// Array's representation.
551+
type OwnedRepr<A> = Vec<A>;
552+
553+
/// RcArray's representation.
554+
type OwnedRcRepr<A> = Rc<Vec<A>>;
555+
550556
/// Array view’s representation.
551557
#[derive(Copy, Clone)]
552558
// This is just a marker type, to carry the lifetime parameter.

0 commit comments

Comments
 (0)