Skip to content

Commit

Permalink
Rename DataRaw* traits to RawData*
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner314 committed Nov 29, 2018
1 parent c81ccdd commit 218bb88
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
58 changes: 29 additions & 29 deletions src/data_traits.rs
Expand Up @@ -27,10 +27,10 @@ use {
/// does not imply any ownership or lifetime; pointers to elements in the array
/// may not be safe to dereference.
///
/// ***Note:*** `DataRaw` is not an extension interface at this point.
/// ***Note:*** `RawData` is not an extension interface at this point.
/// Traits in Rust can serve many different roles. This trait is public because
/// it is used as a bound on public methods.
pub unsafe trait DataRaw : Sized {
pub unsafe trait RawData : Sized {
/// The array element type.
type Elem;

Expand All @@ -45,8 +45,8 @@ pub unsafe trait DataRaw : Sized {
///
/// For an array with writable elements.
///
/// ***Internal trait, see `DataRaw`.***
pub unsafe trait DataRawMut : DataRaw {
/// ***Internal trait, see `RawData`.***
pub unsafe trait RawDataMut : RawData {
/// If possible, ensures that the array has unique access to its data.
///
/// If `Self` provides safe mutable access to array elements, then it
Expand All @@ -68,8 +68,8 @@ pub unsafe trait DataRawMut : DataRaw {
///
/// An array representation that can be cloned.
///
/// ***Internal trait, see `DataRaw`.***
pub unsafe trait DataRawClone : DataRaw {
/// ***Internal trait, see `RawData`.***
pub unsafe trait RawDataClone : RawData {
#[doc(hidden)]
/// Unsafe because, `ptr` must point inside the current storage.
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem);
Expand All @@ -86,8 +86,8 @@ pub unsafe trait DataRawClone : DataRaw {
///
/// For an array with elements that can be accessed with safe code.
///
/// ***Internal trait, see `DataRaw`.***
pub unsafe trait Data : DataRaw {
/// ***Internal trait, see `RawData`.***
pub unsafe trait Data : RawData {
/// Converts the array to a uniquely owned array, cloning elements if necessary.
#[doc(hidden)]
fn into_owned<D>(self_: ArrayBase<Self, D>) -> ArrayBase<OwnedRepr<Self::Elem>, D>
Expand All @@ -105,10 +105,10 @@ pub unsafe trait Data : DataRaw {
// # For implementers
//
// If you implement the `DataMut` trait, you are guaranteeing that the
// `DataRawMut::try_ensure_unique` implementation always panics or ensures that
// `RawDataMut::try_ensure_unique` implementation always panics or ensures that
// the data is unique. You are also guaranteeing that `try_is_unique` always
// returns `Some(_)`.
pub unsafe trait DataMut : Data + DataRawMut {
pub unsafe trait DataMut : Data + RawDataMut {
/// Ensures that the array has unique access to its data.
#[doc(hidden)]
#[inline]
Expand All @@ -133,35 +133,35 @@ pub unsafe trait DataMut : Data + DataRawMut {
/// accessed with safe code.
///
/// ***Internal trait, see `Data`.***
#[deprecated(note="use `Data + DataRawClone` instead", since="0.13")]
pub trait DataClone : Data + DataRawClone {}
#[deprecated(note="use `Data + RawDataClone` instead", since="0.13")]
pub trait DataClone : Data + RawDataClone {}

#[allow(deprecated)]
impl<T> DataClone for T where T: Data + DataRawClone {}
impl<T> DataClone for T where T: Data + RawDataClone {}

unsafe impl<A> DataRaw for RawViewRepr<*const A> {
unsafe impl<A> RawData for RawViewRepr<*const A> {
type Elem = A;
fn _data_slice(&self) -> Option<&[A]> {
None
}
private_impl!{}
}

unsafe impl<A> DataRawClone for RawViewRepr<*const A> {
unsafe impl<A> RawDataClone for RawViewRepr<*const A> {
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
(*self, ptr)
}
}

unsafe impl<A> DataRaw for RawViewRepr<*mut A> {
unsafe impl<A> RawData for RawViewRepr<*mut A> {
type Elem = A;
fn _data_slice(&self) -> Option<&[A]> {
None
}
private_impl!{}
}

unsafe impl<A> DataRawMut for RawViewRepr<*mut A> {
unsafe impl<A> RawDataMut for RawViewRepr<*mut A> {
#[inline]
fn try_ensure_unique<D>(_: &mut ArrayBase<Self, D>)
where Self: Sized,
Expand All @@ -174,13 +174,13 @@ unsafe impl<A> DataRawMut for RawViewRepr<*mut A> {
}
}

unsafe impl<A> DataRawClone for RawViewRepr<*mut A> {
unsafe impl<A> RawDataClone for RawViewRepr<*mut A> {
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
(*self, ptr)
}
}

unsafe impl<A> DataRaw for OwnedArcRepr<A> {
unsafe impl<A> RawData for OwnedArcRepr<A> {
type Elem = A;
fn _data_slice(&self) -> Option<&[A]> {
Some(&self.0)
Expand All @@ -189,7 +189,7 @@ unsafe impl<A> DataRaw for OwnedArcRepr<A> {
}

// NOTE: Copy on write
unsafe impl<A> DataRawMut for OwnedArcRepr<A>
unsafe impl<A> RawDataMut for OwnedArcRepr<A>
where
A: Clone,
{
Expand Down Expand Up @@ -246,22 +246,22 @@ unsafe impl<A> Data for OwnedArcRepr<A> {

unsafe impl<A> DataMut for OwnedArcRepr<A> where A: Clone {}

unsafe impl<A> DataRawClone for OwnedArcRepr<A> {
unsafe impl<A> RawDataClone for OwnedArcRepr<A> {
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
// pointer is preserved
(self.clone(), ptr)
}
}

unsafe impl<A> DataRaw for OwnedRepr<A> {
unsafe impl<A> RawData for OwnedRepr<A> {
type Elem = A;
fn _data_slice(&self) -> Option<&[A]> {
Some(&self.0)
}
private_impl!{}
}

unsafe impl<A> DataRawMut for OwnedRepr<A> {
unsafe impl<A> RawDataMut for OwnedRepr<A> {
#[inline]
fn try_ensure_unique<D>(_: &mut ArrayBase<Self, D>)
where Self: Sized,
Expand All @@ -287,7 +287,7 @@ unsafe impl<A> Data for OwnedRepr<A> {

unsafe impl<A> DataMut for OwnedRepr<A> { }

unsafe impl<A> DataRawClone for OwnedRepr<A>
unsafe impl<A> RawDataClone for OwnedRepr<A>
where A: Clone
{
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
Expand All @@ -313,7 +313,7 @@ unsafe impl<A> DataRawClone for OwnedRepr<A>
}
}

unsafe impl<'a, A> DataRaw for ViewRepr<&'a A> {
unsafe impl<'a, A> RawData for ViewRepr<&'a A> {
type Elem = A;
fn _data_slice(&self) -> Option<&[A]> {
None
Expand All @@ -331,21 +331,21 @@ unsafe impl<'a, A> Data for ViewRepr<&'a A> {
}
}

unsafe impl<'a, A> DataRawClone for ViewRepr<&'a A> {
unsafe impl<'a, A> RawDataClone for ViewRepr<&'a A> {
unsafe fn clone_with_ptr(&self, ptr: *mut Self::Elem) -> (Self, *mut Self::Elem) {
(*self, ptr)
}
}

unsafe impl<'a, A> DataRaw for ViewRepr<&'a mut A> {
unsafe impl<'a, A> RawData for ViewRepr<&'a mut A> {
type Elem = A;
fn _data_slice(&self) -> Option<&[A]> {
None
}
private_impl!{}
}

unsafe impl<'a, A> DataRawMut for ViewRepr<&'a mut A> {
unsafe impl<'a, A> RawDataMut for ViewRepr<&'a mut A> {
#[inline]
fn try_ensure_unique<D>(_: &mut ArrayBase<Self, D>)
where Self: Sized,
Expand Down Expand Up @@ -389,7 +389,7 @@ pub unsafe trait DataOwned : Data {
/// A representation that is a lightweight view.
///
/// ***Internal trait, see `Data`.***
pub unsafe trait DataShared : Clone + Data + DataRawClone { }
pub unsafe trait DataShared : Clone + Data + RawDataClone { }

unsafe impl<A> DataShared for OwnedRcRepr<A> {}
unsafe impl<'a, A> DataShared for ViewRepr<&'a A> {}
Expand Down
2 changes: 1 addition & 1 deletion src/impl_1d.rs
Expand Up @@ -12,7 +12,7 @@ use imp_prelude::*;

/// # Methods For 1-D Arrays
impl<A, S> ArrayBase<S, Ix1>
where S: DataRaw<Elem=A>,
where S: RawData<Elem=A>,
{
/// Return an vector with the elements of the one-dimensional array.
pub fn to_vec(&self) -> Vec<A>
Expand Down
2 changes: 1 addition & 1 deletion src/impl_2d.rs
Expand Up @@ -12,7 +12,7 @@ use imp_prelude::*;

/// # Methods For 2-D Arrays
impl<A, S> ArrayBase<S, Ix2>
where S: DataRaw<Elem=A>,
where S: RawData<Elem=A>,
{
/// Return an array view of row `index`.
///
Expand Down
6 changes: 3 additions & 3 deletions src/impl_clone.rs
Expand Up @@ -6,9 +6,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use imp_prelude::*;
use DataRawClone;
use RawDataClone;

impl<S: DataRawClone, D: Clone> Clone for ArrayBase<S, D> {
impl<S: RawDataClone, D: Clone> Clone for ArrayBase<S, D> {
fn clone(&self) -> ArrayBase<S, D> {
unsafe {
let (data, ptr) = self.data.clone_with_ptr(self.ptr);
Expand All @@ -33,4 +33,4 @@ impl<S: DataRawClone, D: Clone> Clone for ArrayBase<S, D> {
}
}

impl<S: DataRawClone + Copy, D: Copy> Copy for ArrayBase<S, D> {}
impl<S: RawDataClone + Copy, D: Copy> Copy for ArrayBase<S, D> {}
10 changes: 5 additions & 5 deletions src/impl_methods.rs
Expand Up @@ -47,7 +47,7 @@ use stacking::stack;
/// # Methods For All Array Types
impl<A, S, D> ArrayBase<S, D>
where
S: DataRaw<Elem = A>,
S: RawData<Elem = A>,
D: Dimension,
{
/// Return the total number of elements in the array.
Expand Down Expand Up @@ -503,7 +503,7 @@ where
}

pub(crate) fn get_ptr_mut<I>(&mut self, index: I) -> Option<*mut A>
where S: DataRawMut,
where S: RawDataMut,
I: NdIndex<D>,
{
// const and mut are separate to enforce &mutness as well as the
Expand Down Expand Up @@ -1143,7 +1143,7 @@ where
///
/// This method is mostly only useful with unsafe code.
fn try_ensure_unique(&mut self)
where S: DataRawMut
where S: RawDataMut
{
debug_assert!(self.pointer_is_inbounds());
S::try_ensure_unique(self);
Expand Down Expand Up @@ -1204,7 +1204,7 @@ where
/// Return a mutable pointer to the first element in the array.
#[inline(always)]
pub fn as_mut_ptr(&mut self) -> *mut A
where S: DataRawMut
where S: RawDataMut
{
self.try_ensure_unique(); // for RcArray
self.ptr
Expand All @@ -1219,7 +1219,7 @@ where
/// Return a raw mutable view of the array.
#[inline]
pub fn raw_view_mut(&mut self) -> RawArrayViewMut<A, D>
where S: DataRawMut
where S: RawDataMut
{
self.try_ensure_unique(); // for RcArray
unsafe { RawArrayViewMut::new_(self.ptr, self.dim.clone(), self.strides.clone()) }
Expand Down
2 changes: 1 addition & 1 deletion src/impl_raw_views.rs
Expand Up @@ -89,7 +89,7 @@ where
self.ptr
} else {
let offset = stride_offset(index, self.strides.axis(axis));
// The `.offset()` is safe due to the guarantees of `DataRaw`.
// The `.offset()` is safe due to the guarantees of `RawData`.
unsafe { self.ptr.offset(offset) }
};

Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Expand Up @@ -153,9 +153,9 @@ pub use aliases::*;

#[allow(deprecated)]
pub use data_traits::{
DataRaw,
DataRawMut,
DataRawClone,
RawData,
RawDataMut,
RawDataClone,
Data,
DataMut,
DataOwned,
Expand Down Expand Up @@ -197,8 +197,8 @@ mod imp_prelude {
pub use ArcArray;
pub use {
RemoveAxis,
DataRaw,
DataRawMut,
RawData,
RawDataMut,
Data,
DataMut,
DataOwned,
Expand Down Expand Up @@ -1031,7 +1031,7 @@ pub type Ixs = isize;
//
// [`.offset()`]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.offset-1
pub struct ArrayBase<S, D>
where S: DataRaw
where S: RawData
{
/// Data buffer / ownership information. (If owned, contains the data
/// buffer; if borrowed, contains the lifetime and mutability.)
Expand Down

0 comments on commit 218bb88

Please sign in to comment.