From 6bc960a5f6407b03becb696d9f4f9a43efce2319 Mon Sep 17 00:00:00 2001 From: Adam Nemecek Date: Tue, 26 Mar 2019 13:00:44 -0700 Subject: [PATCH 1/3] use self --- src/array.rs | 10 +++++----- src/dim4.rs | 8 ++++---- src/error.rs | 2 +- src/graphics.rs | 8 ++++---- src/index.rs | 6 +++--- src/seq.rs | 4 ++-- src/util.rs | 14 +++++++------- src/vision/mod.rs | 8 ++++---- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/array.rs b/src/array.rs index 6ea64c42d..db2b55a15 100644 --- a/src/array.rs +++ b/src/array.rs @@ -173,7 +173,7 @@ where /// print(&indices); /// ``` #[allow(unused_mut)] - pub fn new(slice: &[T], dims: Dim4) -> Array { + pub fn new(slice: &[T], dims: Dim4) -> Self { let aftype = T::get_af_dtype(); let mut temp: i64 = 0; unsafe { @@ -193,7 +193,7 @@ where /// /// The data pointed by the slice passed to this function can possibily be offseted using an additional `offset` parameter. #[allow(unused_mut)] - pub fn new_strided(slice: &[T], offset: i64, dims: Dim4, strides: Dim4) -> Array { + pub fn new_strided(slice: &[T], offset: i64, dims: Dim4, strides: Dim4) -> Self { let aftype = T::get_af_dtype(); let mut temp: i64 = 0; unsafe { @@ -221,7 +221,7 @@ where /// let garbageVals = Array::::new_empty(Dim4::new(&[3, 1, 1, 1])); /// ``` #[allow(unused_mut)] - pub fn new_empty(dims: Dim4) -> Array { + pub fn new_empty(dims: Dim4) -> Self { let aftype = T::get_af_dtype(); unsafe { let mut temp: i64 = 0; @@ -375,7 +375,7 @@ where /// Makes an copy of the Array /// /// This does a deep copy of the data into a new Array - pub fn copy(&self) -> Array { + pub fn copy(&self) -> Self { unsafe { let mut temp: i64 = 0; let err_val = af_copy_array(&mut temp as MutAfArray, self.handle as AfArray); @@ -522,7 +522,7 @@ impl Clone for Array where T: HasAfEnum, { - fn clone(&self) -> Array { + fn clone(&self) -> Self { unsafe { let mut temp: i64 = 0; let ret_val = af_retain_array(&mut temp as MutAfArray, self.handle as AfArray); diff --git a/src/dim4.rs b/src/dim4.rs index 97d78f7bb..cda469997 100644 --- a/src/dim4.rs +++ b/src/dim4.rs @@ -9,8 +9,8 @@ pub struct Dim4 { /// Default trait for Dim4 returns an Array of dimensions [1, 1, 1, 1] impl Default for Dim4 { - fn default() -> Dim4 { - Dim4 { dims: [1, 1, 1, 1] } + fn default() -> Self { + Self { dims: [1, 1, 1, 1] } } } @@ -64,8 +64,8 @@ impl Dim4 { /// use arrayfire::Dim4; /// let dims = Dim4::new(&[4, 4, 2, 1]); /// ``` - pub fn new(dims: &[u64; 4]) -> Dim4 { - Dim4 { dims: dims.clone() } + pub fn new(dims: &[u64; 4]) -> Self { + Self { dims: dims.clone() } } /// Get the number of elements represented by Dim4 object diff --git a/src/error.rs b/src/error.rs index 9e3680bf9..a685d50a4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -24,7 +24,7 @@ pub struct Callback { impl Callback { /// Associated function to create a new Callback object pub fn new(callback: ErrorCallback) -> Self { - Callback { cb: callback } + Self { cb: callback } } /// call invokes the error callback with `error_code`. diff --git a/src/graphics.rs b/src/graphics.rs index 3bf245a8a..7110b0ad2 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -174,8 +174,8 @@ pub struct Window { /// Used to create Window object from native(ArrayFire) resource handle impl From for Window { - fn from(t: u64) -> Window { - Window { + fn from(t: u64) -> Self { + Self { handle: t, row: -1, col: -1, @@ -212,7 +212,7 @@ impl Window { /// /// Window Object #[allow(unused_mut)] - pub fn new(width: i32, height: i32, title: String) -> Window { + pub fn new(width: i32, height: i32, title: String) -> Self { unsafe { let mut temp: u64 = 0; let cstr_ret = CString::new(title); @@ -225,7 +225,7 @@ impl Window { cstr.as_ptr(), ); HANDLE_ERROR(AfError::from(err_val)); - Window::from(temp) + Self::from(temp) } Err(_) => { panic!("String creation failed while prepping params for window creation.") diff --git a/src/index.rs b/src/index.rs index 8d6ec9df2..6798dd097 100644 --- a/src/index.rs +++ b/src/index.rs @@ -155,13 +155,13 @@ where impl<'object> Indexer<'object> { #[allow(unused_mut)] /// Create a new Indexer object and set the dimension specific index objects later - pub fn new() -> Indexer<'object> { + pub fn new() -> Self { let mut temp: i64 = 0; unsafe { let err_val = af_create_indexers(&mut temp as MutAfIndex); HANDLE_ERROR(AfError::from(err_val)); } - Indexer { + Self { handle: temp, count: 0, marker: PhantomData, @@ -596,7 +596,7 @@ impl SeqInternal { where c_double: From, { - SeqInternal { + Self { begin: From::from(s.begin()), end: From::from(s.end()), step: From::from(s.step()), diff --git a/src/seq.rs b/src/seq.rs index b3d95147a..1e3f52abc 100644 --- a/src/seq.rs +++ b/src/seq.rs @@ -16,7 +16,7 @@ pub struct Seq { /// Default `Seq` spans all the elements along a dimension impl Default for Seq { fn default() -> Self { - Seq { + Self { begin: One::one(), end: One::one(), step: Zero::zero(), @@ -38,7 +38,7 @@ impl fmt::Display for Seq { impl Seq { /// Create a `Seq` that goes from `begin` to `end` at a step size of `step` pub fn new(begin: T, end: T, step: T) -> Self { - Seq { + Self { begin: begin, end: end, step: step, diff --git a/src/util.rs b/src/util.rs index 68ebe7060..f23c4f148 100644 --- a/src/util.rs +++ b/src/util.rs @@ -71,42 +71,42 @@ pub fn free_host(ptr: *mut T) { } impl From for AfError { - fn from(t: i32) -> AfError { + fn from(t: i32) -> Self { assert!(AfError::SUCCESS as i32 <= t && t <= AfError::ERR_UNKNOWN as i32); unsafe { mem::transmute(t) } } } impl From for DType { - fn from(t: u32) -> DType { + fn from(t: u32) -> Self { assert!(DType::F32 as u32 <= t && t <= DType::U64 as u32); unsafe { mem::transmute(t) } } } impl From for InterpType { - fn from(t: u32) -> InterpType { + fn from(t: u32) -> Self { assert!(InterpType::NEAREST as u32 <= t && t <= InterpType::BICUBIC_SPLINE as u32); unsafe { mem::transmute(t) } } } impl From for ConvMode { - fn from(t: u32) -> ConvMode { + fn from(t: u32) -> Self { assert!(ConvMode::DEFAULT as u32 <= t && t <= ConvMode::EXPAND as u32); unsafe { mem::transmute(t) } } } impl From for ConvDomain { - fn from(t: u32) -> ConvDomain { + fn from(t: u32) -> Self { assert!(ConvDomain::AUTO as u32 <= t && t <= ConvDomain::FREQUENCY as u32); unsafe { mem::transmute(t) } } } impl From for MatchType { - fn from(t: u32) -> MatchType { + fn from(t: u32) -> Self { assert!(MatchType::SAD as u32 <= t && t <= MatchType::SHD as u32); unsafe { mem::transmute(t) } } @@ -129,7 +129,7 @@ pub fn to_u32(t: MatProp) -> u32 { } impl From for ColorMap { - fn from(t: u32) -> ColorMap { + fn from(t: u32) -> Self { assert!(ColorMap::DEFAULT as u32 <= t && t <= ColorMap::BLUE as u32); unsafe { mem::transmute(t) } } diff --git a/src/vision/mod.rs b/src/vision/mod.rs index fe634d245..d72602b0c 100644 --- a/src/vision/mod.rs +++ b/src/vision/mod.rs @@ -158,12 +158,12 @@ impl Features { /// /// This object is basically a bunch of Arrays. #[allow(unused_mut)] - pub fn new(n: u64) -> Features { + pub fn new(n: u64) -> Self { unsafe { let mut temp: i64 = 0; let err_val = af_create_features(&mut temp as *mut c_longlong as MutFeat, n as DimT); HANDLE_ERROR(AfError::from(err_val)); - Features { feat: temp } + Self { feat: temp } } } @@ -197,7 +197,7 @@ impl Features { } impl Clone for Features { - fn clone(&self) -> Features { + fn clone(&self) -> Self { unsafe { let mut temp: i64 = 0; let ret_val = af_retain_features( @@ -205,7 +205,7 @@ impl Clone for Features { self.feat as *const c_longlong as Feat, ); HANDLE_ERROR(AfError::from(ret_val)); - Features { feat: temp } + Self { feat: temp } } } } From 83dc9993d94ad733d2a835bbdbbdb1e36c2e6634 Mon Sep 17 00:00:00 2001 From: Adam Nemecek Date: Tue, 26 Mar 2019 14:02:00 -0700 Subject: [PATCH 2/3] self --- src/util.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util.rs b/src/util.rs index f23c4f148..9a9766126 100644 --- a/src/util.rs +++ b/src/util.rs @@ -384,21 +384,21 @@ impl HasAfEnum for u64 { } impl From for SparseFormat { - fn from(t: u32) -> SparseFormat { + fn from(t: u32) -> Self { assert!(SparseFormat::DENSE as u32 <= t && t <= SparseFormat::COO as u32); unsafe { mem::transmute(t) } } } impl From for BinaryOp { - fn from(t: u32) -> BinaryOp { + fn from(t: u32) -> Self { assert!(BinaryOp::ADD as u32 <= t && t <= BinaryOp::MAX as u32); unsafe { mem::transmute(t) } } } impl From for RandomEngineType { - fn from(t: u32) -> RandomEngineType { + fn from(t: u32) -> Self { assert!( RandomEngineType::PHILOX_4X32_10 as u32 <= t && t <= RandomEngineType::MERSENNE_GP11213 as u32 @@ -598,13 +598,13 @@ implicit!(bool, u8 => u8); impl Zero for Complex64 { fn zero() -> Self { - Complex64 { re: 0.0, im: 0.0 } + Self { re: 0.0, im: 0.0 } } } impl Zero for Complex32 { fn zero() -> Self { - Complex32 { re: 0.0, im: 0.0 } + Self { re: 0.0, im: 0.0 } } } From 6039d49c9d456961d29c5d95b1f865557949163b Mon Sep 17 00:00:00 2001 From: Adam Nemecek Date: Tue, 26 Mar 2019 14:08:25 -0700 Subject: [PATCH 3/3] use self --- src/random/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/random/mod.rs b/src/random/mod.rs index d2591da36..a70b285e1 100644 --- a/src/random/mod.rs +++ b/src/random/mod.rs @@ -112,8 +112,8 @@ pub struct RandomEngine { /// Used for creating RandomEngine object from native resource id impl From for RandomEngine { - fn from(t: i64) -> RandomEngine { - RandomEngine { handle: t } + fn from(t: i64) -> Self { + Self { handle: t } } } @@ -128,7 +128,7 @@ impl RandomEngine { /// # Return Values /// /// A object of type RandomEngine - pub fn new(rengine: RandomEngineType, seed: Option) -> RandomEngine { + pub fn new(rengine: RandomEngineType, seed: Option) -> Self { let mut temp: i64 = 0; unsafe { let err_val = af_create_random_engine( @@ -192,7 +192,7 @@ impl RandomEngine { /// Increment reference count of RandomEngine's native resource impl Clone for RandomEngine { - fn clone(&self) -> RandomEngine { + fn clone(&self) -> Self { unsafe { let mut temp: i64 = 0; let err_val =